Last active
February 8, 2023 05:03
-
-
Save Krysztal112233/38eaad2806db29ec669e22e3cabc9079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Nullable | |
@Override | |
public <T extends BlockEntity> BlockEntityTicker<T> getTicker( | |
World world, | |
BlockState state, | |
BlockEntityType<T> type | |
) { | |
return (world1, pos, state1, be) -> | |
((WaterWellBlockEntity) be).tick( | |
world1, | |
pos, | |
state1, | |
(WaterWellBlockEntity) be | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void tick( | |
World world, | |
BlockPos pos, | |
BlockState state, | |
WaterWellBlockEntity entity | |
) { | |
if (world.isClient()) return; | |
if (++tickCount >= maxTickCount) tickCount = 0; else return; | |
this.setWet(world.getBlockState(pos.up()).getBlock() == Blocks.WATER); | |
log.info(new Vec3d(pos.getX(), pos.up(1).getY(), pos.getZ()).toString()); | |
log.info( | |
"{} {} {} {}", | |
this.nitrogenElement, | |
this.phosphorusElement, | |
this.phosphorusElement, | |
this.wet | |
); | |
var itemEntities = world.getEntitiesByClass( | |
ItemEntity.class, | |
Box.from(new Vec3d(pos.getX(), pos.up().getY(), pos.getZ())), | |
EntityPredicates.VALID_ENTITY | |
); | |
for (var itemEntity : itemEntities) { | |
var itemIdentifier = itemEntity | |
.getStack() | |
.getItem() | |
.getIdentifier() | |
.toString(); | |
var combinationOptional = AdvAgriElementResourceManager | |
.getElementRegistry() | |
.stream() | |
.filter($ -> $.getItem().equals(itemIdentifier)) | |
.findFirst(); | |
if (combinationOptional.isEmpty()) continue; | |
var combination = combinationOptional.get(); | |
itemEntity.getStack().decrement(1); // Get item, then decrement it. | |
var elementsCombination = combination.getElementsCombination(); | |
this.nitrogenElement += elementsCombination.getNitrogen(); | |
this.phosphorusElement += elementsCombination.getPhosphorus(); | |
this.potassiumElement += elementsCombination.getPotassium(); | |
break; | |
} | |
this.markDirty(); | |
if (!world.isClient()) ((ServerWorld) world).getChunkManager() | |
.markForUpdate(pos); | |
} | |
@Override | |
protected void writeNbt(NbtCompound nbt) { | |
this.setPotassiumElement(nbt.getInt("PotassiumElement")); | |
this.setPhosphorusElement(nbt.getInt("PhosphorusElement")); | |
this.setNitrogenElement(nbt.getInt("NitrogenElement")); | |
this.setWet(nbt.getBoolean("Wet")); | |
super.writeNbt(nbt); | |
} | |
@Nullable | |
@Override | |
public BlockEntityUpdateS2CPacket toUpdatePacket() { | |
return BlockEntityUpdateS2CPacket.create(this); | |
} | |
@Override | |
public NbtCompound toInitialChunkDataNbt() { | |
NbtCompound compound = new NbtCompound(); | |
super.writeNbt(compound); | |
writeNbt(compound); | |
return compound; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment