Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 6, 2024
1 parent 0ca6435 commit 86c2dd9
Show file tree
Hide file tree
Showing 44 changed files with 316 additions and 335 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.cyclops.colossalchests;

import net.minecraft.advancements.CriterionTrigger;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.cyclops.colossalchests.advancement.criterion.ChestFormedTrigger;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.colossalchests.blockentity.BlockEntityInterface;
import org.cyclops.colossalchests.blockentity.BlockEntityUncolossalChest;
import org.cyclops.colossalchests.inventory.container.ContainerColossalChest;
import org.cyclops.colossalchests.inventory.container.ContainerUncolossalChest;
import org.cyclops.cyclopscore.config.DeferredHolderCommon;

/**
* Referenced registry entries.
* @author rubensworks
*/
public class RegistryEntries {

public static final DeferredHolderCommon<Item, Item> ITEM_CHEST = DeferredHolderCommon.create(Registries.ITEM, ResourceLocation.parse("minecraft:chest"));

public static final DeferredHolderCommon<Block, Block> BLOCK_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK, ResourceLocation.parse("colossalchests:uncolossal_chest"));

public static final DeferredHolderCommon<BlockEntityType<?>, BlockEntityType<BlockEntityColossalChest>> BLOCK_ENTITY_COLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:colossal_chest"));
public static final DeferredHolderCommon<BlockEntityType<?>, BlockEntityType<BlockEntityInterface>> BLOCK_ENTITY_INTERFACE = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:interface"));
public static final DeferredHolderCommon<BlockEntityType<?>, BlockEntityType<BlockEntityUncolossalChest>> BLOCK_ENTITY_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("colossalchests:uncolossal_chest"));

public static final DeferredHolderCommon<MenuType<?>, MenuType<ContainerColossalChest>> CONTAINER_COLOSSAL_CHEST = DeferredHolderCommon.create(Registries.MENU, ResourceLocation.parse("colossalchests:colossal_chest"));
public static final DeferredHolderCommon<MenuType<?>, MenuType<ContainerUncolossalChest>> CONTAINER_UNCOLOSSAL_CHEST = DeferredHolderCommon.create(Registries.MENU, ResourceLocation.parse("colossalchests:uncolossal_chest"));

public static final DeferredHolderCommon<CriterionTrigger<?>, ChestFormedTrigger> TRIGGER_CHEST_FORMED = DeferredHolderCommon.create(Registries.TRIGGER_TYPE, ResourceLocation.parse("colossalchests:chest_formed"));

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.cyclops.colossalchests.advancement.criterion;

import org.cyclops.colossalchests.ColossalChests;
import org.cyclops.cyclopscore.config.extendedconfig.CriterionTriggerConfig;
import org.cyclops.cyclopscore.config.extendedconfig.CriterionTriggerConfigCommon;
import org.cyclops.cyclopscore.init.IModBase;

/**
* @author rubensworks
*
*/
public class ChestFormedTriggerConfig extends CriterionTriggerConfig<ChestFormedTrigger.Instance> {
public class ChestFormedTriggerConfig<M extends IModBase> extends CriterionTriggerConfigCommon<ChestFormedTrigger.Instance, M> {

/**
* Make a new instance.
*/
public ChestFormedTriggerConfig() {
public ChestFormedTriggerConfig(M mod) {
super(
ColossalChests._instance,
mod,
"chest_formed",
new ChestFormedTrigger()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import net.minecraft.world.phys.BlockHitResult;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.cyclopscore.block.multi.CubeDetector;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.cyclopscore.helper.IModHelpers;

/**
* Part of the Colossal Blood Chest multiblock structure.
Expand Down Expand Up @@ -110,7 +110,7 @@ public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean v
Block block = world.getBlockState(location).getBlock();
if(block == this) {
boolean change = !world.getBlockState(location).getValue(ENABLED);
((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), MinecraftHelpers.BLOCK_NOTIFY_CLIENT);
((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), IModHelpers.get().getMinecraftHelpers().getBlockNotifyClient());
if(change) {
BlockEntityColossalChest.detectStructure(world, location, size, valid, originCorner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import org.cyclops.colossalchests.ColossalChests;
import org.cyclops.colossalchests.item.ItemBlockMaterial;
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig;
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon;
import org.cyclops.cyclopscore.init.IModBase;

/**
* Config for the {@link ChestWall}.
* @author rubensworks
*
*/
public class ChestWallConfig extends BlockConfig {
public class ChestWallConfig<M extends IModBase> extends BlockConfigCommon<M> {

public ChestWallConfig(ChestMaterial material) {
public ChestWallConfig(M mod, ChestMaterial material) {
super(
ColossalChests._instance,
mod,
"chest_wall_" + material.getName(),
eConfig -> new ChestWall(Block.Properties.of()
.strength(5.0F)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
Expand All @@ -43,15 +44,12 @@
import net.minecraft.world.phys.Vec3;
import org.cyclops.colossalchests.RegistryEntries;
import org.cyclops.colossalchests.blockentity.BlockEntityColossalChest;
import org.cyclops.cyclopscore.block.BlockWithEntityGui;
import org.cyclops.cyclopscore.block.BlockWithEntityGuiCommon;
import org.cyclops.cyclopscore.block.multi.CubeDetector;
import org.cyclops.cyclopscore.block.multi.DetectionResult;
import org.cyclops.cyclopscore.datastructure.Wrapper;
import org.cyclops.cyclopscore.helper.BlockEntityHelpers;
import org.cyclops.cyclopscore.helper.InventoryHelpers;
import org.cyclops.cyclopscore.helper.LocationHelpers;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.cyclopscore.inventory.SimpleInventory;
import org.cyclops.cyclopscore.helper.IModHelpers;
import org.cyclops.cyclopscore.inventory.SimpleInventoryCommon;
import org.spongepowered.asm.mixin.Interface;

import javax.annotation.Nullable;
Expand All @@ -61,17 +59,17 @@
*
* @author rubensworks
*/
public class ColossalChest extends BlockWithEntityGui implements CubeDetector.IDetectionListener, IBlockChestMaterial {
public class ColossalChest extends BlockWithEntityGuiCommon implements CubeDetector.IDetectionListener, IBlockChestMaterial {

public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED;

private final ChestMaterial material;
public final MapCodec<ColossalChest> codec;

public ColossalChest(Properties properties, ChestMaterial material) {
public ColossalChest(BlockBehaviour.Properties properties, ChestMaterial material) {
super(properties, BlockEntityColossalChest::new);
this.material = material;
this.codec = simpleCodec((props) -> new ColossalChest(props, material));
this.codec = BlockBehaviour.simpleCodec((props) -> new ColossalChest(props, material));

material.setBlockCore(this);

Expand All @@ -88,7 +86,7 @@ public MenuProvider getMenuProvider(BlockState p_49234_, Level p_49235_, BlockPo
@Override
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
return level.isClientSide ? createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.get(), BlockEntityColossalChest::lidAnimateTick) : null;
return level.isClientSide ? BaseEntityBlock.createTickerHelper(blockEntityType, RegistryEntries.BLOCK_ENTITY_COLOSSAL_CHEST.value(), BlockEntityColossalChest::lidAnimateTick) : null;
}

@Override
Expand Down Expand Up @@ -151,13 +149,13 @@ public static DetectionResult triggerDetector(ChestMaterial material, LevelAcces
if (player instanceof ServerPlayer && detectionResult.getError() == null) {
BlockState blockState = world.getBlockState(blockPos);
if (blockState.getValue(ENABLED)) {
BlockEntityColossalChest tile = BlockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class).orElse(null);
BlockEntityColossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntityColossalChest.class).orElse(null);
if (tile == null) {
BlockPos corePos = getCoreLocation(material, world, blockPos);
tile = BlockEntityHelpers.get(world, corePos, BlockEntityColossalChest.class).orElse(null);
tile = IModHelpers.get().getBlockEntityHelpers().get(world, corePos, BlockEntityColossalChest.class).orElse(null);
}

RegistryEntries.TRIGGER_CHEST_FORMED.get().test((ServerPlayer) player, material, tile.getSizeSingular());
RegistryEntries.TRIGGER_CHEST_FORMED.value().test((ServerPlayer) player, material, tile.getSizeSingular());
}
}
return detectionResult;
Expand All @@ -167,7 +165,7 @@ public static DetectionResult triggerDetector(ChestMaterial material, LevelAcces
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.setPlacedBy(world, pos, state, placer, stack);
if (stack.has(DataComponents.CUSTOM_NAME)) {
BlockEntityColossalChest tile = BlockEntityHelpers.get(world, pos, BlockEntityColossalChest.class).orElse(null);
BlockEntityColossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(world, pos, BlockEntityColossalChest.class).orElse(null);
if (tile != null) {
tile.setCustomName(stack.getHoverName());
tile.setSize(Vec3i.ZERO);
Expand All @@ -188,8 +186,8 @@ public void onPlace(BlockState blockStateNew, Level world, BlockPos blockPos, Bl
public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean valid, BlockPos originCorner) {
Block block = world.getBlockState(location).getBlock();
if(block == this) {
((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), MinecraftHelpers.BLOCK_NOTIFY_CLIENT);
BlockEntityColossalChest tile = BlockEntityHelpers.get(world, location, BlockEntityColossalChest.class).orElse(null);
((LevelWriter) world).setBlock(location, world.getBlockState(location).setValue(ENABLED, valid), IModHelpers.get().getMinecraftHelpers().getBlockNotifyClient());
BlockEntityColossalChest tile = IModHelpers.get().getBlockEntityHelpers().get(world, location, BlockEntityColossalChest.class).orElse(null);
if(tile != null) {
tile.setMaterial(this.material);
tile.setSize(valid ? size : Vec3i.ZERO);
Expand Down Expand Up @@ -258,7 +256,7 @@ public static void addPlayerChatError(Player player, Component error) {

@Override
public void writeExtraGuiData(FriendlyByteBuf packetBuffer, Level world, Player player, BlockPos blockPos, BlockHitResult rayTraceResult) {
BlockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class).ifPresent(tile -> packetBuffer.writeInt(tile.getInventory().getContainerSize()));
IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntityColossalChest.class).ifPresent(tile -> packetBuffer.writeInt(tile.getInventory().getContainerSize()));
}

@Override
Expand Down Expand Up @@ -300,11 +298,11 @@ public boolean canSurvive(BlockState blockState, LevelReader world, BlockPos blo
@Override
public void onRemove(BlockState oldState, Level world, BlockPos blockPos, BlockState newState, boolean isMoving) {
if (oldState.getBlock().getClass() != newState.getBlock().getClass()) {
BlockEntityHelpers.get(world, blockPos, BlockEntityColossalChest.class)
IModHelpers.get().getBlockEntityHelpers().get(world, blockPos, BlockEntityColossalChest.class)
.ifPresent(tile -> {
// Last inventory overrides inventory when the chest is in a disabled state.
SimpleInventory lastInventory = tile.getLastValidInventory();
InventoryHelpers.dropItems(world, lastInventory != null ? lastInventory : tile.getInventory(), blockPos);
SimpleInventoryCommon lastInventory = tile.getLastValidInventory();
IModHelpers.get().getInventoryHelpers().dropItems(world, lastInventory != null ? lastInventory : tile.getInventory(), blockPos);
});
super.onRemove(oldState, world, blockPos, newState, isMoving);
}
Expand All @@ -329,7 +327,7 @@ public Component onValidate(BlockPos blockPos, BlockState blockState) {
}
return requiredMaterial.get() == material ? null : Component.translatable(
"multiblock.colossalchests.error.material", Component.translatable(material.getUnlocalizedName()),
LocationHelpers.toCompactString(blockPos),
IModHelpers.get().getLocationHelpers().toCompactString(blockPos),
Component.translatable(requiredMaterial.get().getUnlocalizedName()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.neoforged.fml.config.ModConfig;
import org.cyclops.colossalchests.ColossalChests;
import org.cyclops.colossalchests.item.ItemBlockMaterial;
import org.cyclops.cyclopscore.config.ConfigurableProperty;
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfig;
import org.cyclops.cyclopscore.config.ConfigurablePropertyCommon;
import org.cyclops.cyclopscore.config.ModConfigLocation;
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon;
import org.cyclops.cyclopscore.init.IModBase;

/**
* Config for the {@link ColossalChest}.
* @author rubensworks
*
*/
public class ColossalChestConfig extends BlockConfig {
public class ColossalChestConfig<M extends IModBase> extends BlockConfigCommon<M> {

@ConfigurableProperty(namedId="colossal_chest", category = "machine", comment = "The maximum size a colossal chest can have.", isCommandable = true, configLocation = ModConfig.Type.SERVER)
@ConfigurablePropertyCommon(namedId="colossal_chest", category = "machine", comment = "The maximum size a colossal chest can have.", isCommandable = true, configLocation = ModConfigLocation.SERVER)
public static int maxSize = 20;

@ConfigurableProperty(namedId="colossal_chest", category = "general", comment = "If the chest should visually open when someone uses it.", isCommandable = true, configLocation = ModConfig.Type.CLIENT)
@ConfigurablePropertyCommon(namedId="colossal_chest", category = "general", comment = "If the chest should visually open when someone uses it.", isCommandable = true, configLocation = ModConfigLocation.CLIENT)
public static boolean chestAnimation = true;

public ColossalChestConfig(ChestMaterial material) {
public ColossalChestConfig(M mod, ChestMaterial material) {
super(
ColossalChests._instance,
mod,
"colossal_chest_" + material.getName(),
eConfig -> new ColossalChest(Block.Properties.of()
.strength(5.0F)
Expand Down
Loading

0 comments on commit 86c2dd9

Please sign in to comment.