Skip to content

Commit

Permalink
tree tap accepts only 1 item client fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Mar 18, 2024
1 parent eaa541d commit 0c1e1fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.id.incubus_core.be.InventoryBlockEntity;
import net.id.paradiselost.recipe.ParadiseLostRecipeTypes;
import net.id.paradiselost.recipe.TreeTapRecipe;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -34,15 +36,25 @@ public TreeTapBlockEntity(BlockPos pos, BlockState state) {

public void handleUse(PlayerEntity player, Hand hand, ItemStack handStack) {
ItemStack stored = inventory.get(0);
if (handStack.isEmpty()) {
player.setStackInHand(hand, stored);
inventory.set(0, ItemStack.EMPTY);
} else {
if (!handStack.isEmpty() && inventory.get(0).isEmpty()) {
inventory.set(0, handStack.split(1));
} else {
player.giveItemStack(stored);
inventory.set(0, ItemStack.EMPTY);
}
markDirty();
}

@Override
public boolean canInsert(int slot, ItemStack stack, @Nullable Direction dir) {
return this.getHopperStrategy().canInsert(dir) && this.inventory.get(0).isEmpty();
}

@Override
public boolean canExtract(int slot, ItemStack stack, Direction dir) {
return this.getHopperStrategy().canExtract(dir);
}

@Override
public @NotNull HopperStrategy getHopperStrategy() {
return HopperStrategy.IN_ANY_OUT_BOTTOM;
Expand All @@ -53,10 +65,38 @@ public DefaultedList<ItemStack> getItems() {
return inventory;
}

@Override
public void setStack(int slot, ItemStack stack) {
getItems().set(slot, stack);
if (stack.getCount() > 1) {
stack.setCount(1);
}
inventoryChanged();
System.out.println(getItems());
}

@Override
public ItemStack removeStack(int slot, int count) {
ItemStack stack = Inventories.splitStack(getItems(), slot, count);
inventoryChanged();
return stack;
}

@Override
public ItemStack removeStack(int slot) {
var stack = Inventories.removeStack(getItems(), slot);
inventoryChanged();
return stack;
}

private void inventoryChanged() {
this.markDirty();
if (world != null && !world.isClient) updateInClientWorld();
}

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);

Inventories.readNbt(nbt, inventory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ParadiseLostMiscPlacedFeatures extends ParadiseLostPlacedFeatures {

public static final RegistryEntry<PlacedFeature> ORE_CHERINE = register("ore_cherine", ParadiseLostMiscConfiguredFeatures.ORE_CHERINE, CountPlacementModifier.of(20), SquarePlacementModifier.of(), HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom(0), YOffset.aboveBottom(320)), BiomePlacementModifier.of());
public static final RegistryEntry<PlacedFeature> ORE_OLVITE = register("ore_olvite", ParadiseLostMiscConfiguredFeatures.ORE_OLVITE, CountPlacementModifier.of(16), SquarePlacementModifier.of(), HeightRangePlacementModifier.trapezoid(YOffset.aboveBottom(0), YOffset.aboveBottom(384)), BiomePlacementModifier.of());
public static final RegistryEntry<PlacedFeature> SURTRUM_METEORITE = register("surtrum_meteorite", ParadiseLostMiscConfiguredFeatures.SURTRUM_METEORITE, SquarePlacementModifier.of(), HeightRangePlacementModifier.uniform(YOffset.fixed(65), YOffset.fixed(85)), ChancePlacementModifier.of(150));
public static final RegistryEntry<PlacedFeature> SURTRUM_METEORITE = register("surtrum_meteorite", ParadiseLostMiscConfiguredFeatures.SURTRUM_METEORITE, SquarePlacementModifier.of(), HeightRangePlacementModifier.uniform(YOffset.fixed(65), YOffset.fixed(85)), ChancePlacementModifier.of(255));
// Plato
// Shield
public static final RegistryEntry<PlacedFeature> SHIELD_ROCKS = register("shield_rocks", ParadiseLostMiscConfiguredFeatures.SHIELD_ROCKS, PlacedFeatures.BOTTOM_TO_TOP_RANGE, CountMultilayerPlacementModifier.of(1), CountPlacementModifier.of(UniformIntProvider.create(0, 2)));
Expand Down

0 comments on commit 0c1e1fc

Please sign in to comment.