composting, but fancy

- add the composter as a mechanical arm interaction point
This commit is contained in:
zelophed 2021-02-21 18:12:19 +01:00
parent f6b9d71169
commit 46daa3f699

View file

@ -1,9 +1,5 @@
package com.simibubi.create.content.logistics.block.mechanicalArm;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableMap;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
@ -25,10 +21,10 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBe
import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ComposterBlock;
import net.minecraft.block.JukeboxBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.MusicDiscItem;
@ -50,10 +46,14 @@ import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.InvWrapper;
import javax.annotation.Nullable;
import java.util.function.Supplier;
public abstract class ArmInteractionPoint {
static enum Mode {
enum Mode {
DEPOSIT, TAKE
}
@ -65,20 +65,21 @@ public abstract class ArmInteractionPoint {
private ArmAngleTarget cachedAngles;
private static ImmutableMap<ArmInteractionPoint, Supplier<ArmInteractionPoint>> POINTS =
ImmutableMap.<ArmInteractionPoint, Supplier<ArmInteractionPoint>>builder()
.put(new Saw(), Saw::new)
.put(new Belt(), Belt::new)
.put(new Depot(), Depot::new)
.put(new Chute(), Chute::new)
.put(new Basin(), Basin::new)
.put(new Funnel(), Funnel::new)
.put(new Jukebox(), Jukebox::new)
.put(new Crafter(), Crafter::new)
.put(new Deployer(), Deployer::new)
.put(new Millstone(), Millstone::new)
.put(new BlazeBurner(), BlazeBurner::new)
.put(new CrushingWheels(), CrushingWheels::new)
.build();
ImmutableMap.<ArmInteractionPoint, Supplier<ArmInteractionPoint>>builder()
.put(new Saw(), Saw::new)
.put(new Belt(), Belt::new)
.put(new Depot(), Depot::new)
.put(new Chute(), Chute::new)
.put(new Basin(), Basin::new)
.put(new Funnel(), Funnel::new)
.put(new Jukebox(), Jukebox::new)
.put(new Crafter(), Crafter::new)
.put(new Deployer(), Deployer::new)
.put(new Composter(), Composter::new)
.put(new Millstone(), Millstone::new)
.put(new BlazeBurner(), BlazeBurner::new)
.put(new CrushingWheels(), CrushingWheels::new)
.build();
public ArmInteractionPoint() {
cachedHandler = LazyOptional.empty();
@ -118,8 +119,8 @@ public abstract class ArmInteractionPoint {
ArmAngleTarget getTargetAngles(BlockPos armPos, boolean ceiling) {
if (cachedAngles == null)
cachedAngles =
new ArmAngleTarget(armPos, getInteractionPositionVector(), getInteractionDirection(), ceiling);
cachedAngles = new ArmAngleTarget(armPos, getInteractionPositionVector(), getInteractionDirection(), ceiling);
return cachedAngles;
}
@ -166,8 +167,7 @@ public abstract class ArmInteractionPoint {
for (ArmInteractionPoint armInteractionPoint : POINTS.keySet())
if (armInteractionPoint.isValid(world, pos, state))
point = POINTS.get(armInteractionPoint)
.get();
point = POINTS.get(armInteractionPoint).get();
if (point != null) {
point.state = state;
@ -222,7 +222,7 @@ public abstract class ArmInteractionPoint {
@Override
boolean isValid(IBlockReader reader, BlockPos pos, BlockState state) {
return AllBlocks.MECHANICAL_SAW.has(state) && state.get(SawBlock.FACING) == Direction.UP
&& ((KineticTileEntity) reader.getTileEntity(pos)).getSpeed() != 0;
&& ((KineticTileEntity) reader.getTileEntity(pos)).getSpeed() != 0;
}
}
@ -245,6 +245,25 @@ public abstract class ArmInteractionPoint {
}
static class Composter extends TopFaceArmInteractionPoint {
@Override
Vec3d getInteractionPositionVector() {
return new Vec3d(pos).add(.5f, 13 / 16f, .5f);
}
@Override
boolean isValid(IBlockReader reader, BlockPos pos, BlockState state) {
return Blocks.COMPOSTER.equals(state.getBlock());
}
@Nullable
@Override
IItemHandler getHandler(World world) {
return new InvWrapper(((ComposterBlock) Blocks.COMPOSTER).createInventory(world.getBlockState(pos), world, pos));
}
}
static class Deployer extends ArmInteractionPoint {
@Override
@ -254,14 +273,12 @@ public abstract class ArmInteractionPoint {
@Override
Direction getInteractionDirection() {
return state.get(DeployerBlock.FACING)
.getOpposite();
return state.get(DeployerBlock.FACING).getOpposite();
}
@Override
Vec3d getInteractionPositionVector() {
return super.getInteractionPositionVector()
.add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.65f));
return super.getInteractionPositionVector().add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.65f));
}
}
@ -281,15 +298,13 @@ public abstract class ArmInteractionPoint {
@Override
ItemStack insert(World world, ItemStack stack, boolean simulate) {
ItemStack input = stack.copy();
if (!BlazeBurnerBlock.tryInsert(state, world, pos, input, false, true)
.getResult()
.isEmpty()) {
if (!BlazeBurnerBlock.tryInsert(state, world, pos, input, false, true).getResult().isEmpty()) {
return stack;
}
ActionResult<ItemStack> res = BlazeBurnerBlock.tryInsert(state, world, pos, input, false, simulate);
return res.getType() == ActionResultType.SUCCESS
? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - 1)
: stack;
? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - 1)
: stack;
}
@Override
@ -306,8 +321,7 @@ public abstract class ArmInteractionPoint {
@Override
Direction getInteractionDirection() {
return state.get(MechanicalCrafterBlock.HORIZONTAL_FACING)
.getOpposite();
return state.get(MechanicalCrafterBlock.HORIZONTAL_FACING).getOpposite();
}
@Override
@ -325,8 +339,7 @@ public abstract class ArmInteractionPoint {
@Override
Vec3d getInteractionPositionVector() {
return super.getInteractionPositionVector()
.add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.5f));
return super.getInteractionPositionVector().add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.5f));
}
}
@ -361,8 +374,7 @@ public abstract class ArmInteractionPoint {
return stack;
JukeboxBlock jukeboxBlock = (JukeboxBlock) state.getBlock();
JukeboxTileEntity jukeboxTE = (JukeboxTileEntity) tileEntity;
if (!jukeboxTE.getRecord()
.isEmpty())
if (!jukeboxTE.getRecord().isEmpty())
return stack;
if (!(stack.getItem() instanceof MusicDiscItem))
return stack;
@ -370,7 +382,7 @@ public abstract class ArmInteractionPoint {
ItemStack toInsert = remainder.split(1);
if (!simulate && !world.isRemote) {
jukeboxBlock.insertRecord(world, pos, state, toInsert);
world.playEvent((PlayerEntity) null, 1010, pos, Item.getIdFromItem(toInsert.getItem()));
world.playEvent(null, 1010, pos, Item.getIdFromItem(toInsert.getItem()));
AllTriggers.triggerForNearbyPlayers(AllTriggers.MUSICAL_ARM, world, pos, 10);
}
return remainder;
@ -401,8 +413,7 @@ public abstract class ArmInteractionPoint {
@Override
boolean isValid(IBlockReader reader, BlockPos pos, BlockState state) {
return AllBlocks.BELT.has(state) && !(reader.getBlockState(pos.up())
.getBlock() instanceof BeltTunnelBlock);
return AllBlocks.BELT.has(state) && !(reader.getBlockState(pos.up()).getBlock() instanceof BeltTunnelBlock);
}
}
@ -418,9 +429,7 @@ public abstract class ArmInteractionPoint {
@Override
Vec3d getInteractionPositionVector() {
return VecHelper.getCenterOf(pos)
.add(new Vec3d(FunnelBlock.getFunnelFacing(state)
.getDirectionVec()).scale(-.15f));
return VecHelper.getCenterOf(pos).add(new Vec3d(FunnelBlock.getFunnelFacing(state).getDirectionVec()).scale(-.15f));
}
@Override
@ -435,8 +444,7 @@ public abstract class ArmInteractionPoint {
@Override
Direction getInteractionDirection() {
return FunnelBlock.getFunnelFacing(state)
.getOpposite();
return FunnelBlock.getFunnelFacing(state).getOpposite();
}
@Override