use of com.simibubi.create.foundation.config.CRecipes in project Create by Creators-of-Create.
the class ChromaticCompoundItem method onEntityItemUpdate.
@Override
public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) {
double y = entity.getY();
double yMotion = entity.getDeltaMovement().y;
Level world = entity.level;
CompoundTag data = entity.getPersistentData();
CompoundTag itemData = entity.getItem().getOrCreateTag();
Vec3 positionVec = entity.position();
CRecipes config = AllConfigs.SERVER.recipes;
if (world.isClientSide) {
int light = itemData.getInt("CollectingLight");
if (world.random.nextInt(config.lightSourceCountForRefinedRadiance.get() + 20) < light) {
Vec3 start = VecHelper.offsetRandomly(positionVec, world.random, 3);
Vec3 motion = positionVec.subtract(start).normalize().scale(.2f);
world.addParticle(ParticleTypes.END_ROD, start.x, start.y, start.z, motion.x, motion.y, motion.z);
}
return false;
}
// Convert to Shadow steel if in void
if (y < 0 && y - yMotion < -10 && config.enableShadowSteelRecipe.get()) {
ItemStack newStack = AllItems.SHADOW_STEEL.asStack();
newStack.setCount(stack.getCount());
data.putBoolean("JustCreated", true);
entity.setItem(newStack);
}
if (!config.enableRefinedRadianceRecipe.get())
return false;
// Convert to Refined Radiance if eaten enough light sources
if (itemData.getInt("CollectingLight") >= config.lightSourceCountForRefinedRadiance.get()) {
ItemStack newStack = AllItems.REFINED_RADIANCE.asStack();
ItemEntity newEntity = new ItemEntity(world, entity.getX(), entity.getY(), entity.getZ(), newStack);
newEntity.setDeltaMovement(entity.getDeltaMovement());
newEntity.getPersistentData().putBoolean("JustCreated", true);
itemData.remove("CollectingLight");
world.addFreshEntity(newEntity);
stack.split(1);
entity.setItem(stack);
if (stack.isEmpty())
entity.discard();
return false;
}
// Is inside beacon beam?
boolean isOverBeacon = false;
int entityX = Mth.floor(entity.getX());
int entityZ = Mth.floor(entity.getZ());
int localWorldHeight = world.getHeight(Heightmap.Types.WORLD_SURFACE, entityX, entityZ);
BlockPos.MutableBlockPos testPos = new BlockPos.MutableBlockPos(entityX, Math.min(Mth.floor(entity.getY()), localWorldHeight), entityZ);
while (testPos.getY() > 0) {
testPos.move(Direction.DOWN);
BlockState state = world.getBlockState(testPos);
if (state.getLightBlock(world, testPos) >= 15 && state.getBlock() != Blocks.BEDROCK)
break;
if (state.getBlock() == Blocks.BEACON) {
BlockEntity te = world.getBlockEntity(testPos);
if (!(te instanceof BeaconBlockEntity))
break;
BeaconBlockEntity bte = (BeaconBlockEntity) te;
if (!bte.beamSections.isEmpty())
isOverBeacon = true;
break;
}
}
if (isOverBeacon) {
ItemStack newStack = AllItems.REFINED_RADIANCE.asStack();
newStack.setCount(stack.getCount());
data.putBoolean("JustCreated", true);
entity.setItem(newStack);
return false;
}
// Find a light source and eat it.
Random r = world.random;
int range = 3;
float rate = 1 / 2f;
if (r.nextFloat() > rate)
return false;
BlockPos randomOffset = new BlockPos(VecHelper.offsetRandomly(positionVec, r, range));
BlockState state = world.getBlockState(randomOffset);
TransportedItemStackHandlerBehaviour behaviour = TileEntityBehaviour.get(world, randomOffset, TransportedItemStackHandlerBehaviour.TYPE);
// Find a placed light source
if (behaviour == null) {
if (checkLight(stack, entity, world, itemData, positionVec, randomOffset, state))
world.destroyBlock(randomOffset, false);
return false;
}
// Find a light source from a depot/belt (chunk rebuild safe)
MutableBoolean success = new MutableBoolean(false);
behaviour.handleProcessingOnAllItems(ts -> {
ItemStack heldStack = ts.stack;
if (!(heldStack.getItem() instanceof BlockItem))
return TransportedResult.doNothing();
BlockItem blockItem = (BlockItem) heldStack.getItem();
if (blockItem.getBlock() == null)
return TransportedResult.doNothing();
BlockState stateToCheck = blockItem.getBlock().defaultBlockState();
if (!success.getValue() && checkLight(stack, entity, world, itemData, positionVec, randomOffset, stateToCheck)) {
success.setTrue();
if (ts.stack.getCount() == 1)
return TransportedResult.removeItem();
TransportedItemStack left = ts.copy();
left.stack.shrink(1);
return TransportedResult.convertTo(left);
}
return TransportedResult.doNothing();
});
return false;
}
Aggregations