Skip to content

Commit

Permalink
problem with ctor of shulker box screen handler
Browse files Browse the repository at this point in the history
  • Loading branch information
drkhodakarami committed Nov 18, 2023
1 parent a724739 commit fef65c8
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 1.20.2 2023-11-18T14:15:16.4588291 All That Matters/Tags for minecraft:block
// 1.20.2 2023-11-18T17:24:00.1613035 All That Matters/Tags for minecraft:block
1f9bdd1045dccd95466410e12579545b8cbca675 data\minecraft\tags\blocks\lapis_ores.json
1d31e2156524120781d25e2046706c128e9e445e data\minecraft\tags\blocks\needs_iron_tool.json
6895288c69659b400340acf63661097c3d574c87 data\minecraft\tags\blocks\diamond_ores.json
ccfcb5ecb24b5a9d5e0946cabb8cbbb308c8d5b6 data\minecraft\tags\blocks\copper_ores.json
6077b4e8cc4e148d19a5a4a5f3100cbcdec80b6d data\minecraft\tags\blocks\coal_ores.json
8a23702b05296c8af5014d6aa6e9265ded85c7d9 data\fabric\tags\blocks\needs_tool_level_5.json
1d31e2156524120781d25e2046706c128e9e445e data\minecraft\tags\blocks\needs_iron_tool.json
2316588aa2ba5d989e83a7c566ef671efc7439ed data\minecraft\tags\blocks\mineable\pickaxe.json
182f82d63057c1d8a902c82a6dd797e151f1726d data\c\tags\blocks\gem_blocks.json
6895288c69659b400340acf63661097c3d574c87 data\minecraft\tags\blocks\diamond_ores.json
b0d06695c3b27e22724b2d8ad70fd6ea964e5118 data\minecraft\tags\blocks\needs_stone_tool.json
be68c7cf758c4a85f2a636278e341e901714fc6a data\minecraft\tags\blocks\iron_ores.json
ccfcb5ecb24b5a9d5e0946cabb8cbbb308c8d5b6 data\minecraft\tags\blocks\copper_ores.json
495e39cd6637871f928d4a47f2fbe93cdf282cf5 data\minecraft\tags\blocks\redstone_ores.json
8a23702b05296c8af5014d6aa6e9265ded85c7d9 data\fabric\tags\blocks\needs_tool_level_4.json
6077b4e8cc4e148d19a5a4a5f3100cbcdec80b6d data\minecraft\tags\blocks\coal_ores.json
09a2ae92540badc81ac57242964ad153ba18d077 data\minecraft\tags\blocks\needs_diamond_tool.json
8a23702b05296c8af5014d6aa6e9265ded85c7d9 data\fabric\tags\blocks\needs_tool_level_4.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-11-18T14:15:16.4428382 All That Matters/Block Loot Tables
// 1.20.2 2023-11-18T17:24:00.1492969 All That Matters/Block Loot Tables
f55017dc588353c031ec3b0e0bc97ba94d592c39 data\allthatmatters\loot_tables\blocks\ore_nether_iron.json
f887ca04c0dfcdb62e56c72d195c096b023061dc data\allthatmatters\loot_tables\blocks\ore_end_sapphire.json
85cb66e6c2b06d692e11e67c503ae5ef6cc53d1f data\allthatmatters\loot_tables\blocks\ore_nether_copper.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-11-18T14:15:16.4418392 All That Matters/Tags for minecraft:item
// 1.20.2 2023-11-18T17:24:00.1482982 All That Matters/Tags for minecraft:item
572d7d80d10f03c8d6f51e2925a9ea3b372fe5be data\c\tags\items\casts.json
3234976729a598e706a52e4c0b5936fd6dba9911 data\minecraft\tags\items\swords.json
78af564205e8c82467224b545583d00b3e08dc27 data\allthatmatters\tags\items\smeltery.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-11-18T14:15:16.4438382 All That Matters/Model Definitions
// 1.20.2 2023-11-18T17:24:00.1512962 All That Matters/Model Definitions
b78797ac06939db80100f4503a8e82b10af97f8c assets\allthatmatters\models\item\tool_ruby_sword.json
a99398a6ba0eb50d349987ad956cc5521a8f9bc1 assets\allthatmatters\models\item\armor_copper_chestplate_copper_trim.json
ffea7bf5ed6426d9d81e5e15ff28d4eb9ae073dc assets\allthatmatters\models\item\armor_ruby_chestplate.json
Expand Down Expand Up @@ -59,8 +59,8 @@ dfadd7491c13897d4fea4c4e2fd99ec076f63f9e assets\allthatmatters\models\item\armor
24b4c9a78fa74110eaa84ef07a23b661387f13e0 assets\allthatmatters\models\item\armor_citrine_leggings_diamond_trim.json
2d4013a77e1973e4bea746bf4bb2ca68babcbc04 assets\allthatmatters\models\item\armor_enderite_chestplate_emerald_trim.json
5fe1becc62ee8f3bf06d268e4d4bd8035d6ec8d9 assets\allthatmatters\models\item\tool_sapphire_axe.json
493db8eb15cde839c133645e31a55c4e0eeabd34 assets\allthatmatters\models\item\armor_enderite_helmet_gold_trim.json
47d78f4275a73d2115cd55ab78b5f61ad93ee88d assets\allthatmatters\models\item\armor_citrine_leggings_gold_trim.json
493db8eb15cde839c133645e31a55c4e0eeabd34 assets\allthatmatters\models\item\armor_enderite_helmet_gold_trim.json
23876932378154e7db5d737f2c54c7af97eda0c4 assets\allthatmatters\models\item\armor_ruby_leggings_quartz_trim.json
38dc9c3217d50c455141884b7a8a5d7f4e03bae9 assets\allthatmatters\models\item\armor_enderite_chestplate_diamond_trim.json
ec9f921acfe2ea8c6a52f8810f44392992256b0c assets\allthatmatters\models\item\head_netherite_shovel.json
Expand Down Expand Up @@ -95,8 +95,8 @@ e8dad44f8b9caa6674072b7cdd67a939a7f313fa assets\allthatmatters\models\item\armor
59382e8c060d86da25f15236222a7fb24d1f796f assets\allthatmatters\models\item\head_netherite_hoe.json
cc4581f25a7b064ba34293c761d9dcf91558b694 assets\allthatmatters\models\item\armor_amethyst_chestplate_emerald_trim.json
725a56d1e3ca1360782d3871f65e5d12e5b5f541 assets\allthatmatters\models\item\armor_emerald_chestplate_copper_trim.json
de58f06b9612e1589ab97f0b3ebb306faf2965a7 assets\allthatmatters\models\block\ore_deep_sapphire.json
d9411587bb45b3cfdc5be5b5ea92680e3a7b18de assets\allthatmatters\models\item\armor_sapphire_chestplate_netherite_trim.json
de58f06b9612e1589ab97f0b3ebb306faf2965a7 assets\allthatmatters\models\block\ore_deep_sapphire.json
90da0bdc6ee4c87afff3f31e2c4ba894e5fc2f8e assets\allthatmatters\models\item\armor_sapphire_leggings_redstone_trim.json
f96e78714a12c02e979ae6afdd82ae9a636246fa assets\allthatmatters\models\item\armor_amethyst_chestplate_redstone_trim.json
7aee19025169b6a5c59bc72feed5ac2404e65ade assets\allthatmatters\models\item\armor_amethyst_chestplate_lapis_trim.json
Expand Down Expand Up @@ -157,8 +157,8 @@ e5bb9d08d01327e0a5f39d38cb8339fd308f54c7 assets\allthatmatters\models\item\head_
2d5e313e3ed72bfa52e4219dc71612f4ef36c767 assets\allthatmatters\models\item\head_copper_sword.json
6ff14a88fb53e60f840216372a8e047e879b8193 assets\allthatmatters\models\item\tool_ruby_pickaxe.json
6229b9f9e88960766a33626e8298db279cb800c1 assets\allthatmatters\models\item\tool_netherite_hammer.json
743a54ef37df4dedbe96016ffeb20b4cf2c6aed4 assets\allthatmatters\models\item\armor_amethyst_helmet_quartz_trim.json
83c80afcd41c3d9733cc7bda5c81a76536daf2e9 assets\allthatmatters\models\item\raw_sapphire.json
743a54ef37df4dedbe96016ffeb20b4cf2c6aed4 assets\allthatmatters\models\item\armor_amethyst_helmet_quartz_trim.json
9f10691c44a0a04d41d91d5406ea4685e9feb239 assets\allthatmatters\models\item\tool_citrine_axe.json
3438eeb9d92b82cbbfddff55abc774345499aed6 assets\allthatmatters\models\item\armor_citrine_helmet_netherite_trim.json
65bc3a6bcb5753934644054ad288f89ae45c5b73 assets\allthatmatters\models\item\armor_amethyst_leggings_iron_trim.json
Expand Down Expand Up @@ -349,8 +349,8 @@ d0e24cbba1dde5d0fb0d51bb7d62008e78c96378 assets\allthatmatters\models\item\armor
011a6a32541755d5f3de3b4e4d7069b01115caf9 assets\allthatmatters\models\item\armor_sapphire_boots_redstone_trim.json
e5afc78f1fe535c427dfe543bc35988376130f63 assets\allthatmatters\models\item\tool_citrine_sword.json
6db5186249a73a8d798a055a117d3751e9e28dab assets\allthatmatters\models\item\armor_amethyst_leggings_gold_trim.json
746af3d907a058ede2e3ccaaae6b3dd62c32a30c assets\allthatmatters\models\item\armor_ruby_leggings_amethyst_trim.json
cabde16ebe3c89465793ac3112ee3df2500debe3 assets\allthatmatters\models\item\armor_enderite_helmet_redstone_trim.json
746af3d907a058ede2e3ccaaae6b3dd62c32a30c assets\allthatmatters\models\item\armor_ruby_leggings_amethyst_trim.json
e9f2e55730950b97e4e709a7b04a4e8fa41430da assets\allthatmatters\models\item\tool_enderite_pickaxe.json
b830b85cd3aba5f24ea7ac43fab01b28f239484c assets\allthatmatters\models\item\head_copper_shovel.json
bc69517a1972aede80872249000c388f4cb6f231 assets\allthatmatters\models\item\armor_emerald_helmet_copper_trim.json
Expand Down Expand Up @@ -422,8 +422,8 @@ a9b35cca05dfd422035dfd2f5637c214a18e1148 assets\allthatmatters\models\item\armor
505af0b11a86c5508aaeb171175624baeb1a252c assets\allthatmatters\models\item\ore_deep_citrine.json
90df57ccabfd52a2b1843451ea5a888c8f71153c assets\allthatmatters\models\item\gear_prismarine.json
0fa03d18f57eeb720af72c13fdddfa9df0231695 assets\allthatmatters\models\item\armor_citrine_leggings_netherite_trim.json
0654878a487dc14b3c373857d6bbb8833ef5cc4e assets\allthatmatters\models\item\head_netherite_sword.json
2b8983749fbef9e0d3fb50e24e46790746dfb099 assets\allthatmatters\models\block\ore_enderite.json
0654878a487dc14b3c373857d6bbb8833ef5cc4e assets\allthatmatters\models\item\head_netherite_sword.json
af65387e568dc60eb896b32e108a75a050a425a2 assets\allthatmatters\models\item\armor_ruby_chestplate_quartz_trim.json
fb51e8c3bfe0fca615814e81fae0bd20f350de3b assets\allthatmatters\models\block\ore_end_citrine.json
f16ea7340b439e8ff6b6f0c29785c5c18394fb94 assets\allthatmatters\models\item\ore_world_sapphire.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-11-18T14:15:16.43884 All That Matters/allthatmatters
// 1.20.2 2023-11-18T17:24:00.1453008 All That Matters/allthatmatters
30f27ba590246e575f59f5cb66c03477dc8cc8de data\allthatmatters\worldgen\configured_feature\ore_ruby.json
0da71feddc9be599dd4bcd66c7244dee4a84c269 data\allthatmatters\worldgen\configured_feature\ore_nether_copper.json
b74a342ad43adb06b8e2cdf2fc59fa4911133aa3 data\allthatmatters\worldgen\configured_feature\ore_nether_citrine.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.2 2023-11-18T14:15:16.4248503 All That Matters/Recipes
// 1.20.2 2023-11-18T17:24:00.1323062 All That Matters/Recipes
f0e134e54e902372ddec9fc749c8937d08d424cc data\allthatmatters\recipes\enderite_shulker_pinkshaped.json
be6d5410d3c4e24a47e69b9d1755c749d2ecb717 data\allthatmatters\recipes\enderite_shulker_light_grayshapeless.json
50e770715c18b7eef9739df81cb97f75d2e25918 data\allthatmatters\recipes\enderite_shulker_purpleshaped.json
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/jiraiyah/allthatmatters/AllThatMatters.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,6 @@ public void onInitialize()
{
LOGGER.info(">>> Initializing");

/*ServerWorldEvents.LOAD.register((world, entity) ->
{
var server = world.getOverworld().getServer();
ModStatsHandler stats = ModStatsHandler.getServerState(server);
if (!stats.worldCreated)
{
BlockState blockState;
var blockStates = BlockPos.iterate(-500, 40, -500, 500, 130, 500);
var overworld = world.getOverworld();
for (var position : blockStates)
{
blockState = overworld.getBlockState(position);
if (blockState.isOf(Blocks.GRASS) || blockState.isOf(Blocks.TALL_GRASS))
overworld.setBlockState(position, Blocks.AIR.getDefaultState());
}
stats.worldCreated = true;
stats.markDirty();
}
});*/

ModTicker.initialize();
ModItems.register();
ModBlocks.register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ public static void register()
//endregion

FluidStorage.SIDED.registerForBlockEntity((entity, direction) -> entity.fluidStorage, GEM_CLEANSER);
FluidStorage.SIDED.registerForBlockEntity((entity, direction) -> entity.fluidStorage, SMELTERY);
FluidStorage.SIDED.registerForBlockEntity((entity, direction) -> entity.leftFluidStorage, ENDERITE_SHULKER);
FluidStorage.SIDED.registerForBlockEntity((entity, direction) -> entity.rightFluidStorage, ENDERITE_SHULKER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@

import jiraiyah.allthatmatters.block.ModBlockEntities;
import jiraiyah.allthatmatters.block.custom.EnderiteShulkerBoxBlock;
import jiraiyah.allthatmatters.networking.ModMessages;
import jiraiyah.allthatmatters.utils.ModTags;
import jiraiyah.allthatmatters.utils.fluid.FluidStack;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes;
import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView;
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.FlowableFluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.collection.DefaultedList;
Expand All @@ -36,8 +38,6 @@

import java.util.stream.IntStream;

import static jiraiyah.allthatmatters.AllThatMatters.LOGGER;

public class EnderiteShulkerBlockEntity extends ShulkerBoxBlockEntity
{
private final int[] AVAILABLE_SLOTS;
Expand Down Expand Up @@ -73,7 +73,7 @@ protected void onFinalCommit()

if (!world.isClient())
{
//sendFluidPacket();
sendFluidPacket();
}
}
};
Expand All @@ -99,20 +99,10 @@ protected void onFinalCommit()

if (!world.isClient())
{
//sendFluidPacket();
sendFluidPacket();
}
}
};










//


Expand Down Expand Up @@ -252,7 +242,7 @@ private void handleFluidTick(World world, BlockPos pos, BlockState state)

private void handleTank(World world, BlockPos pos, BlockState state, SingleVariantStorage<FluidVariant> tank, int inputSlot, int outputSlot)
{
Storage<FluidVariant> slotStorage = ContainerItemContext.withConstant(getStack(inputSlot)).find(FluidStorage.ITEM);
/*Storage<FluidVariant> slotStorage = ContainerItemContext.withConstant(getStack(inputSlot)).find(FluidStorage.ITEM);
if(slotStorage == null)
return;
Item slotItem = getStack(inputSlot).getItem();
Expand All @@ -264,10 +254,30 @@ private void handleTank(World world, BlockPos pos, BlockState state, SingleVaria
catch (Exception e)
{
LOGGER.info(e.getMessage());
}*/

if (!this.isTankEmpty(tank) && isLiquidOutputReceivable(outputSlot))
{
if (this.isItemStackEmptyBucket(inputSlot))
{
this.transferFromTank(tank, inputSlot, outputSlot);
markDirty(world, pos, state);
}
}
if ((this.isTankEmpty(tank) || this.isTankReceivable(tank)) && isLiquidOutputReceivable(outputSlot))
{
if (!this.isItemStackEmptyBucket(inputSlot))
{
if (this.isItemStackCompatibleWithTank(tank, inputSlot))
{
this.transferToTank(tank, Fluids.WATER, Items.BUCKET, inputSlot, outputSlot);
markDirty(world, pos, state);
}
}
}
}

private static boolean moveWithSound(World world, BlockPos pos, Storage<FluidVariant> from, Storage<FluidVariant> to, boolean fill, Item handItem)
/*private static boolean moveWithSound(World world, BlockPos pos, Storage<FluidVariant> from, Storage<FluidVariant> to, boolean fill, Item handItem)
{
for (StorageView<FluidVariant> view : from)
{
Expand Down Expand Up @@ -310,5 +320,100 @@ private static boolean moveWithSound(World world, BlockPos pos, Storage<FluidVar
}
return false;
}*/

private boolean isTankEmpty(SingleVariantStorage<FluidVariant> tank)
{
return tank.amount == 0;
}

private boolean isLiquidOutputReceivable(int outputSlot)
{
return getStack(outputSlot).isEmpty() ||
getStack(outputSlot).getCount() < getStack(outputSlot).getMaxCount();
}

private boolean isItemStackEmptyBucket(int slotIndex)
{
return getStack(slotIndex).isOf(Items.BUCKET);
}

private boolean isTankReceivable(SingleVariantStorage<FluidVariant> tank)
{
return tank.amount <= tank.getCapacity() - 1000;
}

protected boolean isItemStackCompatibleWithTank(SingleVariantStorage<FluidVariant> tank, int slotIndex)
{
long maxExtracted;
long accepted;
long result;
Storage<FluidVariant> slotStorage = ContainerItemContext.withConstant(getStack(slotIndex)).find(FluidStorage.ITEM);

if(slotStorage == null)
return false;

FluidVariant resource = tank.getResource();
try (Transaction extractionTestTransaction = Transaction.openOuter())
{
maxExtracted = slotStorage.extract(resource, Long.MAX_VALUE, extractionTestTransaction);
extractionTestTransaction.abort();
}
try (Transaction extractionTestTransaction = Transaction.openOuter())
{
accepted = tank.insert(resource, maxExtracted, extractionTestTransaction);
result = slotStorage.extract(resource, accepted, extractionTestTransaction);
extractionTestTransaction.abort();
}
return accepted > 0 && result == accepted;
}

private void transferFromTank(SingleVariantStorage<FluidVariant> tank, int inputSlot, int outputSlot)
{
FluidVariant resource = tank.getResource();

Storage<FluidVariant> slotStorage = ContainerItemContext.withConstant(getStack(inputSlot)).find(FluidStorage.ITEM);

try (Transaction transaction = Transaction.openOuter())
{
tank.extract(resource, FluidStack.convertDropletsToMb(FluidConstants.BLOCK), transaction);
slotStorage.insert(resource, FluidStack.convertDropletsToMb(FluidConstants.BLOCK), transaction);
transaction.commit();
SoundEvent sound = FluidVariantAttributes.getFillSound(resource);
world.playSound(pos.getX(), pos.getY(), pos.getZ(), sound, SoundCategory.BLOCKS, 1, 1, true);
ItemStack stack = getStack(inputSlot);
this.removeStack(inputSlot, 1);
this.setStack(outputSlot, new ItemStack(stack.getItem(), getStack(outputSlot).getCount() + 1));
}
}

private void transferToTank(SingleVariantStorage<FluidVariant> tank, FlowableFluid water, Item bucket, int inputSlot, int outputSlot)
{
FluidVariant resource = tank.getResource();

Storage<FluidVariant> slotStorage = ContainerItemContext.withConstant(getStack(inputSlot)).find(FluidStorage.ITEM);

try (Transaction transaction = Transaction.openOuter())
{
slotStorage.extract(resource, FluidStack.convertDropletsToMb(FluidConstants.BLOCK), transaction);
tank.insert(resource, FluidStack.convertDropletsToMb(FluidConstants.BLOCK), transaction);
transaction.commit();
SoundEvent sound = FluidVariantAttributes.getEmptySound(resource);
world.playSound(pos.getX(), pos.getY(), pos.getZ(), sound, SoundCategory.BLOCKS, 1, 1, true);
ItemStack stack = getStack(inputSlot);
this.removeStack(inputSlot, 1);
this.setStack(outputSlot, new ItemStack(stack.getItem(), getStack(outputSlot).getCount() + 1));
}
}

private void sendFluidPacket()
{
PacketByteBuf data = PacketByteBufs.create();
leftFluidStorage.variant.toPacket(data);
rightFluidStorage.variant.toPacket(data);
data.writeLong(leftFluidStorage.amount);
data.writeLong(rightFluidStorage.amount);
data.writeBlockPos(getPos());
ModMessages.sendToClientPlayerEntities(world, getPos(), ModMessages.GEM_CLEANSER_FLUID_SYNC, data);
}
}
Loading

0 comments on commit fef65c8

Please sign in to comment.