Skip to content

Commit

Permalink
feat: nerf fleshkin chest by removing shulkerbox behavior and droppin…
Browse files Browse the repository at this point in the history
…g items on destruction
  • Loading branch information
Elenterius committed Jun 16, 2023
1 parent f379e9f commit 83dc760
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected static LootTable.Builder dropWithInventory(Block block) {
)));
}

protected static LootTable.Builder dropFleshkinChest(Block block) {
protected static LootTable.Builder dropOwnableInventory(Block block) {
return LootTable.lootTable().withPool(applyExplosionCondition(block, LootPool.lootPool().setRolls(ConstantValue.exactly(1))
.add(LootItem.lootTableItem(block)
.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY))
Expand Down Expand Up @@ -78,7 +78,7 @@ protected void addTables() {
add(ModBlocks.DIGESTER.get(), BlockLoot::createNameableBlockEntityTable);
add(ModBlocks.DECOMPOSER.get(), BlockLoot::createNameableBlockEntityTable);

add(ModBlocks.FLESHKIN_CHEST.get(), ModBlockLoot::dropFleshkinChest);
add(ModBlocks.FLESHKIN_CHEST.get(), BlockLoot::createNameableBlockEntityTable);
add(ModBlocks.FLESHKIN_DOOR.get(), ModBlockLoot::dropWithOwnableData);
add(ModBlocks.FLESHKIN_TRAPDOOR.get(), ModBlockLoot::dropWithOwnableData);
add(ModBlocks.FLESHKIN_PRESSURE_PLATE.get(), ModBlockLoot::dropWithOwnableData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.BlockItem;
Expand Down Expand Up @@ -161,17 +160,11 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
}

@Override
public void playerWillDestroy(Level level, BlockPos pos, BlockState state, Player player) {
if (!level.isClientSide && player.isCreative() && level.getBlockEntity(pos) instanceof FleshkinChestBlockEntity chest && !chest.isEmpty()) {
ItemStack stack = new ItemStack(this);
chest.saveToItem(stack);
if (chest.hasCustomName()) stack.setHoverName(chest.getCustomName());
ItemEntity itemEntity = new ItemEntity(level, pos.getX() + 0.5d, pos.getY() + 0.5D, pos.getZ() + 0.5d, stack);
itemEntity.setDefaultPickUpDelay();
level.addFreshEntity(itemEntity);
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
if (!level.isClientSide && !state.is(newState.getBlock()) && level.getBlockEntity(pos) instanceof FleshkinChestBlockEntity chest) {
chest.dropContainerContents(level, pos);
}

super.playerWillDestroy(level, pos, state, player);
super.onRemove(state, level, pos, newState, isMoving);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.github.elenterius.biomancy.init.ModBlockEntities;
import com.github.elenterius.biomancy.init.ModDamageSources;
import com.github.elenterius.biomancy.init.ModSoundEvents;
import com.github.elenterius.biomancy.inventory.BehavioralInventory;
import com.github.elenterius.biomancy.inventory.itemhandler.HandlerBehaviors;
import com.github.elenterius.biomancy.inventory.SimpleInventory;
import com.github.elenterius.biomancy.inventory.menu.FleshkinChestMenu;
import com.github.elenterius.biomancy.network.ISyncableAnimation;
import com.github.elenterius.biomancy.network.ModNetworkHandler;
Expand All @@ -18,6 +17,7 @@
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class FleshkinChestBlockEntity extends OwnableContainerBlockEntity implem

public static final int SLOTS = 6 * 7;

private final BehavioralInventory<?> inventory;
private final SimpleInventory inventory;
private final AnimationFactory animationFactory = GeckoLibUtil.createFactory(this);
private final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() {
@Override
Expand Down Expand Up @@ -83,7 +83,7 @@ protected boolean isOwnContainer(Player player) {

public FleshkinChestBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.FLESHKIN_CHEST.get(), pos, state);
inventory = BehavioralInventory.createServerContents(SLOTS, HandlerBehaviors::denyItemWithFilledInventory, this::canPlayerOpenContainer, this::setChanged);
inventory = SimpleInventory.createServerContents(SLOTS, this::canPlayerOpenContainer, this::setChanged);
inventory.setOpenInventoryConsumer(this::startOpen);
inventory.setCloseInventoryConsumer(this::stopOpen);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public void load(CompoundTag tag) {

@Override
public void dropContainerContents(Level level, BlockPos pos) {
// Containers.dropContents(level, pos, inventory);
if (!inventory.isEmpty()) Containers.dropContents(level, pos, inventory);
}

public boolean isEmpty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,44 @@
import com.github.elenterius.biomancy.BiomancyMod;
import com.github.elenterius.biomancy.block.fleshkinchest.FleshkinChestBlockEntity;
import com.github.elenterius.biomancy.init.ModMenuTypes;
import com.github.elenterius.biomancy.inventory.BehavioralInventory;
import com.github.elenterius.biomancy.inventory.SimpleInventory;
import com.github.elenterius.biomancy.inventory.slot.ISlotZone;
import com.github.elenterius.biomancy.inventory.slot.NonNestingSlot;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.apache.logging.log4j.MarkerManager;

public class FleshkinChestMenu extends PlayerContainerMenu {

private final BehavioralInventory<?> inventory;
protected final Level level;
private final SimpleInventory inventory;

protected FleshkinChestMenu(int id, Inventory playerInventory, BehavioralInventory<?> inventory) {
protected FleshkinChestMenu(int id, Inventory playerInventory, SimpleInventory chestInventory) {
super(ModMenuTypes.FLESHKIN_CHEST.get(), id, playerInventory, 150, 208);
level = playerInventory.player.level;

this.inventory = inventory;
this.inventory.startOpen(playerInventory.player);
inventory = chestInventory;
inventory.startOpen(playerInventory.player);

final int posX = 26;
final int posY = 24;
final int rows = 6;
final int columns = 7;
int posX = 26;
int posY = 24;
int rows = 6;
int columns = 7;
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
addSlot(new NonNestingSlot(this.inventory, y * columns + x, posX + x * 18, posY + y * 18));
addSlot(new Slot(inventory, y * columns + x, posX + x * 18, posY + y * 18));
}
}
}

public static FleshkinChestMenu createServerMenu(int screenId, Inventory playerInventory, BehavioralInventory<?> inventory) {
return new FleshkinChestMenu(screenId, playerInventory, inventory);
public static FleshkinChestMenu createServerMenu(int screenId, Inventory playerInventory, SimpleInventory chestInventory) {
return new FleshkinChestMenu(screenId, playerInventory, chestInventory);
}

public static FleshkinChestMenu createClientMenu(int screenId, Inventory playerInventory, FriendlyByteBuf extraData) {
BehavioralInventory<?> inventory = BehavioralInventory.createClientContents(FleshkinChestBlockEntity.SLOTS);
return new FleshkinChestMenu(screenId, playerInventory, inventory);
SimpleInventory chestInventory = SimpleInventory.createClientContents(FleshkinChestBlockEntity.SLOTS);
return new FleshkinChestMenu(screenId, playerInventory, chestInventory);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public FleshkinChestBlockItem(Block block, Properties properties) {

@Override
public boolean canFitInsideContainerItems() {
return false;
return true;
}

// public boolean canFitInsideContainerItems(ItemStack stack) {
Expand Down

0 comments on commit 83dc760

Please sign in to comment.