use of net.minecraft.block.properties.IProperty in project Wizardry by TeamWizardry.
the class FluidRecipeBuilder method buildFluidCrafter.
public static FluidCrafter buildFluidCrafter(String identifier, ItemStack outputItem, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp, boolean instant) {
Ingredient outputIngredient = Ingredient.fromStacks(outputItem);
List<Ingredient> inputs = Lists.newArrayList(extraInputs);
return new FluidCrafter((world, pos, items) -> {
if (allLiquidInPool(world, pos, required, fluid).size() < required)
return false;
List<ItemStack> list = items.stream().map(entity -> entity.getItem().copy()).collect(Collectors.toList());
List<Ingredient> inputList = new ArrayList<>(inputs);
inputList.add(input);
for (Ingredient itemIn : inputList) {
boolean foundMatch = false;
List<ItemStack> toRemove = new LinkedList<>();
for (ItemStack item : list) {
if (itemIn.apply(item) && !outputIngredient.apply(item)) {
foundMatch = true;
item.shrink(1);
if (item.isEmpty())
toRemove.add(item);
break;
}
}
if (!foundMatch)
return false;
list.removeAll(toRemove);
toRemove.clear();
}
return true;
}, (world, pos, items, currentDuration) -> {
EntityItem entityItem = items.stream().filter(entity -> input.apply(entity.getItem())).findFirst().orElse(null);
if (entityItem != null) {
if (world.isRemote)
LibParticles.CRAFTING_ALTAR_IDLE(world, entityItem.getPositionVector());
if (bubbling && currentDuration % 10 == 0)
world.playSound(null, entityItem.posX, entityItem.posY, entityItem.posZ, ModSounds.BUBBLING, SoundCategory.BLOCKS, 0.7F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
}
}, (world, pos, items, currentDuration) -> {
if (consume) {
Block block = fluid.getBlock();
if (block != null) {
IBlockState defaultState = block.getDefaultState();
Iterator<IProperty<?>> properties = defaultState.getPropertyKeys().iterator();
IBlockState drainState = defaultState;
if (properties.hasNext())
drainState = drainState.cycleProperty(properties.next());
for (BlockPos position : allLiquidInPool(world, pos, required, fluid)) world.setBlockState(position, drainState);
}
}
List<Ingredient> inputList = new ArrayList<>(inputs);
inputList.add(input);
int count = 0;
recipeLoop: {
boolean itemFound = false;
do {
for (Ingredient itemIn : inputList) {
for (EntityItem entity : items) {
if (itemIn.apply(entity.getItem()) && !outputIngredient.apply(entity.getItem())) {
entity.getItem().shrink(1);
if (entity.getItem().isEmpty())
entity.setDead();
break;
}
}
}
count += outputItem.getCount();
for (Ingredient itemIn : inputList) {
itemFound = false;
for (EntityItem entity : items) {
if (itemIn.apply(entity.getItem()) && !outputIngredient.apply(entity.getItem())) {
itemFound = true;
break;
}
}
if (!itemFound)
break recipeLoop;
}
} while (duration == 0 && !consume && instant && itemFound);
}
EntityItem output;
do {
output = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, outputItem.copy());
output.getItem().setCount(Math.min(count, outputItem.getMaxStackSize()));
output.motionX = 0;
output.motionY = 0;
output.motionZ = 0;
output.forceSpawn = true;
world.spawnEntity(output);
count -= outputItem.getMaxStackSize();
} while (count > 0);
if (explode) {
PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output.getPositionVector(), Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.posX, output.posY, output.posZ, 256));
PosUtils.boom(world, output.getPositionVector(), output, 3, false);
}
if (harp)
world.playSound(null, output.posX, output.posY, output.posZ, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
}, identifier, duration).setInputs(input, inputs).setOutput(outputItem).setDoesConsume(consume).setRequired(required).setFluid(fluid);
}
use of net.minecraft.block.properties.IProperty in project Wizardry by TeamWizardry.
the class FluidRecipeBuilder method buildFluidCrafter.
public static FluidCrafter buildFluidCrafter(String identifier, IBlockState outputBlock, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp) {
List<Ingredient> inputs = Lists.newArrayList(extraInputs);
FluidCrafter builder = new FluidCrafter((world, pos, items) -> {
if (allLiquidInPool(world, pos, required, fluid).size() < required)
return false;
List<ItemStack> list = items.stream().map(entity -> entity.getItem().copy()).collect(Collectors.toList());
List<Ingredient> inputList = new ArrayList<>(inputs);
inputList.add(input);
for (Ingredient itemIn : inputList) {
boolean foundMatch = false;
List<ItemStack> toRemove = new LinkedList<>();
for (ItemStack item : list) {
if (itemIn.apply(item)) {
foundMatch = true;
item.shrink(1);
if (item.isEmpty())
toRemove.add(item);
break;
}
}
if (!foundMatch)
return false;
list.removeAll(toRemove);
toRemove.clear();
}
return true;
}, (world, pos, items, currentDuration) -> {
EntityItem entityItem = items.stream().filter(entity -> input.apply(entity.getItem())).findFirst().orElse(null);
if (entityItem != null) {
if (world.isRemote)
LibParticles.CRAFTING_ALTAR_IDLE(world, entityItem.getPositionVector());
if (bubbling && currentDuration % 10 == 0)
world.playSound(null, entityItem.posX, entityItem.posY, entityItem.posZ, ModSounds.BUBBLING, SoundCategory.BLOCKS, 0.7F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
}
}, (world, pos, items, currentDuration) -> {
if (consume) {
Block block = fluid.getBlock();
if (block != null) {
IBlockState defaultState = block.getDefaultState();
Iterator<IProperty<?>> properties = defaultState.getPropertyKeys().iterator();
IBlockState drainState = defaultState;
if (properties.hasNext())
drainState = drainState.cycleProperty(properties.next());
for (BlockPos position : allLiquidInPool(world, pos, required, fluid)) world.setBlockState(position, drainState);
}
}
List<Ingredient> inputList = new ArrayList<>(inputs);
inputList.add(input);
for (Ingredient itemIn : inputList) {
for (EntityItem entity : items) {
if (itemIn.apply(entity.getItem())) {
entity.getItem().shrink(1);
if (entity.getItem().isEmpty())
entity.setDead();
}
}
}
world.setBlockState(pos, outputBlock);
Vec3d output = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
if (explode) {
PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output, Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.x, output.y, output.z, 256));
PosUtils.boom(world, output, null, 3, false);
}
if (harp)
world.playSound(null, output.x, output.y, output.z, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
}, identifier, duration).setInputs(input, inputs).setIsBlock(true).setDoesConsume(true).setRequired(required).setFluid(fluid);
Fluid fluidOutput = FluidRegistry.lookupFluidForBlock(outputBlock.getBlock());
if (fluidOutput != null)
builder.setOutput(new FluidStack(fluidOutput, 1000));
else
builder.setOutput(new ItemStack(outputBlock.getBlock(), 1, outputBlock.getBlock().damageDropped(outputBlock)));
return builder;
}
use of net.minecraft.block.properties.IProperty in project Solar by ArekkuusuJerii.
the class TileMechanicalTranslocator method getRotationState.
private IBlockState getRotationState(IBlockState original, EnumFacing from, EnumFacing to) {
ProfilerHelper.begin("[Mechanical Translocator] Rotating block");
boolean hasProperty = false;
for (IProperty<?> p : original.getPropertyKeys()) {
if (p.getValueClass().equals(EnumFacing.class) && p.getName().toLowerCase(Locale.ROOT).contains("facing")) {
hasProperty = true;
// noinspection unchecked
IProperty<EnumFacing> property = (IProperty<EnumFacing>) p;
EnumFacing actual = original.getValue(property);
original = apply(property, original, FacingHelper.rotate(actual, from, to));
break;
}
}
if (!hasProperty) {
// uwu
original = original.withRotation(FacingHelper.getHorizontalRotation(from, to));
}
ProfilerHelper.end();
return original;
}
Aggregations