diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index c64ecd7aa..27706b043 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -144,7 +144,6 @@ public class ActuallyAdditions { eventBus.addListener(ActuallyAdditionsClient::setupMenus); eventBus.addListener(ActuallyAdditionsClient::setupSpecialRenders); eventBus.addListener(ActuallyAdditionsClient::registerParticleFactories); - eventBus.register(new ClientRegistryHandler()); } IFarmerBehavior.initBehaviors(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java index a367a2b7a..42715df97 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java @@ -1,7 +1,9 @@ package de.ellpeck.actuallyadditions.mod; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; +import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; @@ -29,10 +31,10 @@ public class ActuallyTabs { .filter(stack -> stack.getItem() instanceof ItemEnergy).toList(); charged.forEach(stack -> { if(stack.getItem() instanceof ItemEnergy itemEnergy) { -// CustomEnergyStorage storage = new CustomEnergyStorage(itemEnergy.maxPower, itemEnergy.transfer, itemEnergy.transfer); -// storage.setEnergyStored(itemEnergy.maxPower); -// stack.setData(ActuallyComponents.ENERGY_STORAGE.get(), storage); -// stack.getOrCreateTag().putBoolean("Charged", true); TODO: IMPORTANT: ADD BACK THE CREATIVE ITEMS! + CustomEnergyStorage storage = new CustomEnergyStorage(itemEnergy.maxPower, itemEnergy.transfer, itemEnergy.transfer); + storage.setEnergyStored(itemEnergy.maxPower); + stack.set(ActuallyComponents.ENERGY_STORAGE.get(), storage); + stack.getOrCreateTag().putBoolean("Charged", true); } }); stacks.addAll(charged); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java deleted file mode 100644 index fd74a3b57..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.ellpeck.actuallyadditions.mod; - -import net.minecraft.client.resources.model.ModelResourceLocation; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.material.Fluid; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.neoforge.client.event.ModelEvent.BakingCompleted; -import net.neoforged.neoforge.client.event.ModelEvent.RegisterGeometryLoaders; - -import java.util.HashMap; -import java.util.Map; - -/** - * TODO: [port] eval all of this class - */ -public class ClientRegistryHandler { - - public static final Map MODEL_LOCATIONS_FOR_REGISTERING = new HashMap<>(); - - /** - * (Excerpted from Tinkers' Construct with permission, thanks guys!) - */ - private static void registerCustomFluidBlockRenderer(Fluid fluid) { - // Block block = fluid.getBlock(); - // Item item = Item.getItemFromBlock(block); - // FluidStateMapper mapper = new FluidStateMapper(fluid); - // ModelBakery.registerItemVariants(item); - // ModelLoader.setCustomMeshDefinition(item, mapper); - // ModelLoader.setCustomStateMapper(block, mapper); - } - - @SubscribeEvent - public void onModelRegistry(RegisterGeometryLoaders event) { - // for (Block block : RegistryHandler.BLOCKS_TO_REGISTER) { - // if (block instanceof IHasModel) { - // ((IHasModel) block).registerRendering(); - // } - // } - // - // for (Map.Entry entry : MODEL_LOCATIONS_FOR_REGISTERING.entrySet()) { - // ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue()); - // } - // - // registerCustomFluidBlockRenderer(InitFluids.fluidCanolaOil); - // registerCustomFluidBlockRenderer(InitFluids.fluidRefinedCanolaOil); - // registerCustomFluidBlockRenderer(InitFluids.fluidCrystalOil); - // registerCustomFluidBlockRenderer(InitFluids.fluidEmpoweredOil); - } - - @SubscribeEvent - public void onModelBake(BakingCompleted e) { - // ModelResourceLocation mrl = new ModelResourceLocation(ActuallyAdditions.modLoc("block_compost"), "normal"); - // CompostModel.compostBase = e.getModelRegistry().getObject(mrl); - // e.getModelRegistry().putObject(mrl, new ActualCompostModel()); - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/RegistryHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/RegistryHandler.java deleted file mode 100644 index 0b878cf71..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/RegistryHandler.java +++ /dev/null @@ -1,79 +0,0 @@ -// TODO: [port] remove all of this -//package de.ellpeck.actuallyadditions.mod; -// -//import java.util.ArrayList; -//import java.util.List; -// -//import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; -//import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; -//import de.ellpeck.actuallyadditions.mod.crafting.InitCrafting; -//import de.ellpeck.actuallyadditions.mod.gen.village.InitVillager; -//import de.ellpeck.actuallyadditions.mod.items.InitItems; -//import de.ellpeck.actuallyadditions.mod.misc.SoundHandler; -//import de.ellpeck.actuallyadditions.mod.ore.InitOreDict; -//import net.minecraft.block.Block; -//import net.minecraft.item.Item; -//import net.minecraft.item.crafting.IRecipe; -//import net.minecraft.util.SoundEvent; -//import net.minecraftforge.event.RegistryEvent.Register; -//import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -//import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession; -// -////Class to wrap around the trainwreck that is the new registry system -//public class RegistryHandler { -// -// public static final List BLOCKS_TO_REGISTER = new ArrayList<>(); -// public static final List ITEMS_TO_REGISTER = new ArrayList<>(); -// public static final List SOUNDS_TO_REGISTER = new ArrayList<>(); -// public static final List RECIPES_TO_REGISTER = new ArrayList<>(); -// -// @SubscribeEvent -// public void onBlockRegistry(Register event) { -// InitBlocks.init(); -// -// for (Block block : BLOCKS_TO_REGISTER) { -// event.getRegistry().register(block); -// } -// } -// -// @SubscribeEvent -// public void onItemRegistry(Register event) { -// InitItems.init(); -// -// for (Item item : ITEMS_TO_REGISTER) { -// event.getRegistry().register(item); -// } -// ITEMS_TO_REGISTER.clear(); -// -// //Hack to make this register before recipes :> -// InitOreDict.init(); -// } -// -// @SubscribeEvent -// public void onVillagerRegistry(Register event) { -// InitVillager.init(); -// -// if (ConfigBoolValues.JAM_VILLAGER_EXISTS.isEnabled()) event.getRegistry().register(InitVillager.jamProfession); -// if (ConfigBoolValues.ENGINEER_VILLAGER_EXISTS.isEnabled()) event.getRegistry().register(InitVillager.engineerProfession); -// } -// -// @SubscribeEvent -// public void onCraftingRegistry(Register event) { -// InitCrafting.init(); -// -// for (IRecipe recipe : RECIPES_TO_REGISTER) { -// event.getRegistry().register(recipe); -// } -// RECIPES_TO_REGISTER.clear(); -// } -// -// @SubscribeEvent -// public void onSoundRegistry(Register event) { -// SoundHandler.init(); -// -// for (SoundEvent sound : SOUNDS_TO_REGISTER) { -// event.getRegistry().register(sound); -// } -// SOUNDS_TO_REGISTER.clear(); -// } -//} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Filler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Filler.java index 19a43ae38..9ac0cf23a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Filler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Filler.java @@ -13,8 +13,13 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.Util; +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -24,6 +29,7 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -60,13 +66,13 @@ public class Filler extends ItemEnergy { } private static void saveData(BlockState state, ItemStack wand) { -// wand.getOrCreateTag().put("state", NbtUtils.writeBlockState(state)); TODO: IMPORTANT: Fix Filler Item! + wand.getOrCreateTag().put("state", NbtUtils.writeBlockState(state)); } private static Optional loadData(ItemStack stack) { -// if (stack.getOrCreateTag().contains("state")) { -// return Optional.of(NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), stack.getOrCreateTag().getCompound("state"))); -// } + if (stack.getOrCreateTag().contains("state")) { + return Optional.of(NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), stack.getOrCreateTag().getCompound("state"))); + } return Optional.empty(); } @@ -84,16 +90,16 @@ public class Filler extends ItemEnergy { saveData(state, stack); return InteractionResult.SUCCESS; } else if (loadData(stack).isPresent()) { -// CompoundTag compound = stack.getOrCreateTag(); -// -// if (compound.getInt("CurrX") == 0 && compound.getInt("CurrY") == 0 && compound.getInt("CurrZ") == 0) { -// compound.putInt("FirstX", context.getClickedPos().getX()); -// compound.putInt("FirstY", context.getClickedPos().getY()); -// compound.putInt("FirstZ", context.getClickedPos().getZ()); -// -// context.getPlayer().startUsingItem(context.getHand()); -// return InteractionResult.SUCCESS; -// } + CompoundTag compound = stack.getOrCreateTag(); + + if (compound.getInt("CurrX") == 0 && compound.getInt("CurrY") == 0 && compound.getInt("CurrZ") == 0) { + compound.putInt("FirstX", context.getClickedPos().getX()); + compound.putInt("FirstY", context.getClickedPos().getY()); + compound.putInt("FirstZ", context.getClickedPos().getZ()); + + context.getPlayer().startUsingItem(context.getHand()); + return InteractionResult.SUCCESS; + } } } return super.useOn(context); @@ -106,20 +112,20 @@ public class Filler extends ItemEnergy { if (entity instanceof Player player) { HitResult result = player.pick(Util.getReachDistance(player), 1f, false); if (result instanceof BlockHitResult) { -// CompoundTag compound = stack.getOrCreateTag(); -// -// BlockPos pos = ((BlockHitResult) result).getBlockPos(); -// compound.putInt("SecondX", pos.getX()); -// compound.putInt("SecondY", pos.getY()); -// compound.putInt("SecondZ", pos.getZ()); -// -// clear = false; + CompoundTag compound = stack.getOrCreateTag(); + + BlockPos pos = ((BlockHitResult) result).getBlockPos(); + compound.putInt("SecondX", pos.getX()); + compound.putInt("SecondY", pos.getY()); + compound.putInt("SecondZ", pos.getZ()); + + clear = false; } } if (clear) { -// ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ"); - } //TODO: HOOK BACK UP!!!!!!!!!!!!!!!!!!!!!!! + ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ"); + } } super.releaseUsing(stack, world, entity, timeLeft); @@ -133,80 +139,80 @@ public class Filler extends ItemEnergy { if (!world.isClientSide) { boolean shouldClear = false; -// if (isSelected) { -// if (entity instanceof Player player && stack.hasTag()) { -// boolean creative = player.isCreative(); -// -// CompoundTag compound = stack.getOrCreateTag(); -// -// BlockPos firstPos = new BlockPos(compound.getInt("FirstX"), compound.getInt("FirstY"), compound.getInt("FirstZ")); -// BlockPos secondPos = new BlockPos(compound.getInt("SecondX"), compound.getInt("SecondY"), compound.getInt("SecondZ")); -// -// if (!BlockPos.ZERO.equals(firstPos) && !BlockPos.ZERO.equals(secondPos)) { -// int energyUse = 1500; -// -// Optional data = loadData(stack); -// if (data.isPresent() && (creative || this.getEnergyStored(stack) >= energyUse)) { -// BlockState replaceState = data.get(); // not the best way to do this. -// int lowestX = Math.min(firstPos.getX(), secondPos.getX()); -// int lowestY = Math.min(firstPos.getY(), secondPos.getY()); -// int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ()); -// -// int currX = compound.getInt("CurrX"); -// int currY = compound.getInt("CurrY"); -// int currZ = compound.getInt("CurrZ"); -// -// BlockPos pos = new BlockPos(lowestX + currX, lowestY + currY, lowestZ + currZ); -// BlockState state = world.getBlockState(pos); -// -// if (state.canBeReplaced() && replaceState.canSurvive(world, pos)) { -// if (creative || removeFittingItem(replaceState, player)) { -// world.setBlock(pos, replaceState, 2); -// -// SoundType sound = replaceState.getBlock().getSoundType(replaceState, world, pos, player); -// world.playSound(null, pos, sound.getPlaceSound(), SoundSource.BLOCKS, sound.getVolume() / 2F + .5F, sound.getPitch() * 0.8F); -// -// if (!creative) { -// this.extractEnergy(stack, energyUse, false); -// } -// } else { -// shouldClear = true; -// } -// } -// -// int distX = Math.abs(secondPos.getX() - firstPos.getX()); -// int distY = Math.abs(secondPos.getY() - firstPos.getY()); -// int distZ = Math.abs(secondPos.getZ() - firstPos.getZ()); -// -// currX++; -// if (currX > distX) { -// currX = 0; -// currY++; -// if (currY > distY) { -// currY = 0; -// currZ++; -// if (currZ > distZ) { -// shouldClear = true; -// } -// } -// } -// -// if (!shouldClear) { -// compound.putInt("CurrX", currX); -// compound.putInt("CurrY", currY); -// compound.putInt("CurrZ", currZ); -// } -// } else { -// shouldClear = true; -// } -// } -// } -// } else { -// shouldClear = true; -// } + if (isSelected) { + if (entity instanceof Player player && stack.hasTag()) { + boolean creative = player.isCreative(); - if (shouldClear) { //TODO: HOOK BACK UP!!!!!!!!!!!!!!!!!!!!!!! -// ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ", "SecondX", "SecondY", "SecondZ", "CurrX", "CurrY", "CurrZ"); + CompoundTag compound = stack.getOrCreateTag(); + + BlockPos firstPos = new BlockPos(compound.getInt("FirstX"), compound.getInt("FirstY"), compound.getInt("FirstZ")); + BlockPos secondPos = new BlockPos(compound.getInt("SecondX"), compound.getInt("SecondY"), compound.getInt("SecondZ")); + + if (!BlockPos.ZERO.equals(firstPos) && !BlockPos.ZERO.equals(secondPos)) { + int energyUse = 1500; + + Optional data = loadData(stack); + if (data.isPresent() && (creative || this.getEnergyStored(stack) >= energyUse)) { + BlockState replaceState = data.get(); // not the best way to do this. + int lowestX = Math.min(firstPos.getX(), secondPos.getX()); + int lowestY = Math.min(firstPos.getY(), secondPos.getY()); + int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ()); + + int currX = compound.getInt("CurrX"); + int currY = compound.getInt("CurrY"); + int currZ = compound.getInt("CurrZ"); + + BlockPos pos = new BlockPos(lowestX + currX, lowestY + currY, lowestZ + currZ); + BlockState state = world.getBlockState(pos); + + if (state.canBeReplaced() && replaceState.canSurvive(world, pos)) { + if (creative || removeFittingItem(replaceState, player)) { + world.setBlock(pos, replaceState, 2); + + SoundType sound = replaceState.getBlock().getSoundType(replaceState, world, pos, player); + world.playSound(null, pos, sound.getPlaceSound(), SoundSource.BLOCKS, sound.getVolume() / 2F + .5F, sound.getPitch() * 0.8F); + + if (!creative) { + this.extractEnergy(stack, energyUse, false); + } + } else { + shouldClear = true; + } + } + + int distX = Math.abs(secondPos.getX() - firstPos.getX()); + int distY = Math.abs(secondPos.getY() - firstPos.getY()); + int distZ = Math.abs(secondPos.getZ() - firstPos.getZ()); + + currX++; + if (currX > distX) { + currX = 0; + currY++; + if (currY > distY) { + currY = 0; + currZ++; + if (currZ > distZ) { + shouldClear = true; + } + } + } + + if (!shouldClear) { + compound.putInt("CurrX", currX); + compound.putInt("CurrY", currY); + compound.putInt("CurrZ", currZ); + } + } else { + shouldClear = true; + } + } + } + } else { + shouldClear = true; + } + + if (shouldClear) { + ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ", "SecondX", "SecondY", "SecondZ", "CurrX", "CurrY", "CurrZ"); } } }