Jump to content

Swordsaint

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by Swordsaint

  1. I have problems registering my custom TNT Entity using deferredRegisters. Basically I have an ambiguity problem (as far as I was able to research). Sadly I haven't really been able to come up with a solution to my problem. I would really appreciate some help, as I have tried a lot of stuff. For example: I tried deleting the second constructor, but then I can't really spawn the custom-primed-TNT when I light my CustomTNT block. Here is the code: Custom TNT Entity: public class InfusedTNTEntity extends TNTEntity { public InfusedTNTEntity(EntityType<? extends InfusedTNTEntity> type, World worldIn) { super(type, worldIn); } public InfusedTNTEntity(World worldIn, double x, double y, double z, @Nullable LivingEntity igniter) { super(worldIn, x, y, z, igniter); } } ModEntities: public class ModEntities { public static final RegistryObject<EntityType<InfusedTNTEntity>> PRIMED_INFUSED_TNT = register("primed_infused_tnt", () -> EntityType.Builder.create(InfusedTNTEntity::new, EntityClassification.MISC).size(0.5F, 0.9F).build(null)); static void register() {} private static <T extends EntityType<?>> RegistryObject<T> register(String name, Supplier<T> entity){ return Registration.ENTITY_TYPES.register(name, entity); } } Edit: I just realized i didn't actually directly specify the problem.. Basically the error message is: error: incompatible types: cannot infer type-variable(s) T public static final RegistryObject<EntityType<InfusedTNTEntity>> PRIMED_INFUSED_TNT = register("primed_infused_tnt", () -> EntityType.Builder.create(InfusedTNTEntity::new, EntityClassification.MISC).size(0.5F, 0.9F).build(null)); ^ (argument mismatch; invalid constructor reference incompatible types: EntityType<Entity> cannot be converted to EntityType<? extends InfusedTNTEntity>) where T is a type-variable: T extends Entity declared in method <T>create(IFactory<T>,EntityClassification)
  2. Thank you! Sadly the capability system is giving me a rough time, it will probably take me some time to understand them completely and be able to use them in the proper way. (I guess they are easy af but i'm just not able to get a grasp of the idea haha).
  3. Well, If i rightclick the tank with a modded item like a tank from "LargeFluidTank", the game crashes due to being unable to cast the Modded Item to Bucket Item. I'll have to gain some experience and fix this bug later.
  4. Thank you! I took some inspiration from the vanilla cauldron and how it handled the logic and this is what i came up with: public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) { ItemStack itemstack = player.getHeldItem(handIn); if (itemstack.isEmpty()) { return ActionResultType.PASS; } else { VoidCollectorTile te = (VoidCollectorTile) worldIn.getTileEntity(pos); Item item = itemstack.getItem(); if (itemstack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent() && item != Items.BUCKET) { BucketItem bi = (BucketItem) itemstack.getItem(); if (te.getTank().getSpace() > 1000 && (bi.getFluid().isEquivalentTo(te.getTank().getFluid().getRawFluid()) || te.getTank().isEmpty()) && !worldIn.isRemote) { if (!player.abilities.isCreativeMode) { player.setHeldItem(handIn, new ItemStack(Items.BUCKET)); } te.getTank().fill(new FluidStack(bi.getFluid(), 1000), IFluidHandler.FluidAction.EXECUTE); worldIn.playSound((PlayerEntity) null, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F); } } else { if (itemstack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent() && te.getTank().getFluidAmount() >= 1000 && !worldIn.isRemote) { if (!player.abilities.isCreativeMode) { itemstack.shrink(1); if (itemstack.isEmpty()) { player.setHeldItem(handIn, FluidUtil.getFilledBucket(new FluidStack(te.getTank().getFluid().getRawFluid(), 1000))); } else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET))) { player.dropItem((FluidUtil.getFilledBucket(new FluidStack(te.getTank().getFluid().getRawFluid(), 1000))), false); } } te.getTank().getFluid().shrink(1000); worldIn.playSound((PlayerEntity) null, pos, SoundEvents.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F); } } return ActionResultType.SUCCESS; } } There's still some things I have to fix. I also still have to test how this interacts with lets say, OpenBlock's tanks (on RightClick). But it really helped me a lot!
  5. Thanks a lot! I came up with this code: public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult p_225533_6_) { ItemStack itemstack = player.getHeldItem(handIn); if(itemstack.getItem() instanceof BucketItem){ VoidCollectorTile te = (VoidCollectorTile) worldIn.getTileEntity(pos); if(te instanceof VoidCollectorTile){ if(itemstack.getItem() != Items.BUCKET){ BucketItem bi = (BucketItem) itemstack.getItem(); te.getTank().fill(new FluidStack(bi.getFluid(), 1000), IFluidHandler.FluidAction.EXECUTE); player.setHeldItem(handIn, new ItemStack(Items.BUCKET)); return ActionResultType.SUCCESS; } else { if(te.getTank().getFluidAmount() < 1000) return ActionResultType.FAIL; te.getTank().drain(1000, IFluidHandler.FluidAction.EXECUTE); //SET PLAYER ITEM IN HANDIN TO BUCKET WITH FLUID IN te.getTank().getFluid() } } return ActionResultType.FAIL; } I have one more problem though, I don't know how to create a Bucketitem with the right fluid (the one from the tank). I fiddled around with the BucketItem constructor and how to use it, but I am unable to come up with an instruction that returns a Bucket filled with the tankfluid. If you could elaborate on how to do it I would be very thankful and this thread would probably be solved.
  6. Yes, the vanilla cauldron doesn't use a tileentity. I want to use one though. Also, in the cauldron only water_bucket works. I basically would like to create a tank like openblock's tank. A tank which can store all types of fluids. The problem is, I have no clue how to check if the player is holding a bucket with fluid in it and how to access the FluidTank in the VoidCollectorTile on BlockActivation.
  7. My goal is to create a simple block, which you can rightclick with a filled bucket. The bucket empties and the block stores the fluid. When you rightclick again (with an empty bucket), the bucket fills with the fluid and the tankblock empties. Pretty basic. Sadly, I'm having a very hard time implementing this. The fluidtank is called voidcollector (placeholder). I have set up a VoidCollector class extending block: public class VoidCollector extends Block { //public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING; public VoidCollector() { super(Properties.create(Material.ROCK)); //this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.SOUTH)); } @Override public boolean hasTileEntity(BlockState state){ return true; } @Nullable @Override public TileEntity createTileEntity(BlockState state, IBlockReader world){ return new VoidCollectorTile(); } } And a VoidCollectorTile class (Basically the example TileFluidHandler): public class VoidCollectorTile extends TileEntity { protected FluidTank tank = new FluidTank(FluidAttributes.BUCKET_VOLUME); private final LazyOptional<IFluidHandler> holder = LazyOptional.of(() -> tank); public VoidCollectorTile() { super(Registration.VOIDCOLLECTOR_TILE.get()); } @Override public void read(CompoundNBT tag) { super.read(tag); tank.readFromNBT(tag); } @Override public CompoundNBT write(CompoundNBT tag) { tag = super.write(tag); tank.writeToNBT(tag); return tag; } @Override @Nonnull public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return holder.cast(); return super.getCapability(capability, facing); } public FluidTank getTank(){ return this.tank; } } My problem is now, that I have absolutely no clue how to implement the bucket functionality. I tried looking at sourcecodes of other mods (some fluid tank mods and openblocks, ..) but without success. I also couldn't find any posts or tutorials that answer my question. I then tried to just do it in the VoidCollector class by overriding onBlockActivation and checking if the player has a bucket in hand. But it 1. didnt work and 2. I highly doubt that thats the correct way to do it. I would be very thankful if someone could help me get a grasp of to implement something like this. Thanks.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.