Skip to content

Commit

Permalink
Abstract implementation to common
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 7, 2024
1 parent 0ca6435 commit eef8b36
Show file tree
Hide file tree
Showing 66 changed files with 928 additions and 699 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ org.gradle.daemon=false
org.gradle.caching=true

# Common dependencies
cyclopscore_version=1.24.0-616
cyclopscore_version=1.24.0-619
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.cyclops.colossalchests;

import org.cyclops.cyclopscore.init.IModBase;

/**
* @author rubensworks
*/
public class ColossalChestsInstance {

public static IModBase MOD = null;

}
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 @@ -6,24 +6,20 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LevelWriter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.FluidState;
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 All @@ -34,7 +30,7 @@ public class ChestWall extends Block implements CubeDetector.IDetectionListener,

public static final BooleanProperty ENABLED = ColossalChest.ENABLED;

private final ChestMaterial material;
protected final ChestMaterial material;

public ChestWall(Block.Properties properties, ChestMaterial material) {
super(properties);
Expand Down Expand Up @@ -72,11 +68,6 @@ public boolean propagatesSkylightDown(BlockState blockState, BlockGetter blockRe
return blockState.getValue(ENABLED);
}

@Override
public boolean shouldDisplayFluidOverlay(BlockState blockState, BlockAndTintGetter world, BlockPos pos, FluidState fluidState) {
return true;
}

@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.setPlacedBy(world, pos, state, placer, stack);
Expand All @@ -86,31 +77,27 @@ public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntit
@Override
public void onPlace(BlockState blockStateNew, Level world, BlockPos blockPos, BlockState blockStateOld, boolean isMoving) {
super.onPlace(blockStateNew, world, blockPos, blockStateOld, isMoving);
if(!world.captureBlockSnapshots && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) {
if(!isCaptureBlockSnapshots(world) && blockStateNew.getBlock() != blockStateOld.getBlock() && !blockStateNew.getValue(ENABLED)) {
ColossalChest.triggerDetector(this.material, world, blockPos, true, null);
}
}

protected boolean isCaptureBlockSnapshots(Level level) {
return false;
}

@Override
public void destroy(LevelAccessor world, BlockPos blockPos, BlockState blockState) {
if(blockState.getValue(ENABLED)) ColossalChest.triggerDetector(material, world, blockPos, false, null);
super.destroy(world, blockPos, blockState);
}

@Override
public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) {
if(world.getBlockState(pos).getValue(ENABLED)) ColossalChest.triggerDetector(material, world, pos, false, null);
// IForgeBlock.super.onBlockExploded(state, world, pos, explosion);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
wasExploded(world, pos, explosion);
}

@Override
public void onDetect(LevelReader world, BlockPos location, Vec3i size, boolean valid, BlockPos originCorner) {
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 All @@ -136,12 +123,4 @@ public boolean canSurvive(BlockState blockState, LevelReader world, BlockPos blo
return super.canSurvive(blockState, world, blockPos) && ColossalChest.canPlace(world, blockPos);
}

@Override
public float getExplosionResistance(BlockState state, BlockGetter world, BlockPos pos, Explosion explosion) {
if (this.material.isExplosionResistant()) {
return 10000F;
}
return 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.cyclops.colossalchests.block;

import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import org.cyclops.cyclopscore.config.extendedconfig.BlockConfigCommon;
import org.cyclops.cyclopscore.init.IModBase;
import org.jetbrains.annotations.Nullable;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
* @author rubensworks
*/
public class ChestWallConfig<M extends IModBase> extends BlockConfigCommon<M> {
public ChestWallConfig(M mod, String namedId, Function<BlockConfigCommon<M>, ? extends Block> blockConstructor, @Nullable BiFunction<BlockConfigCommon<M>, Block, ? extends Item> itemConstructor) {
super(mod, namedId, blockConstructor, itemConstructor);
}

public Block.Properties getProperties() {
return Block.Properties.of()
.strength(5.0F)
.sound(SoundType.WOOD)
.requiresCorrectToolForDrops()
.noOcclusion()
.isValidSpawn((state, level, pos, entityType) -> false);
}
}
Loading

0 comments on commit eef8b36

Please sign in to comment.