mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
composting, but fancy
- add the composter as a mechanical arm interaction point
This commit is contained in:
parent
f6b9d71169
commit
46daa3f699
1 changed files with 57 additions and 49 deletions
|
@ -1,9 +1,5 @@
|
||||||
package com.simibubi.create.content.logistics.block.mechanicalArm;
|
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.google.common.collect.ImmutableMap;
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.simibubi.create.AllBlockPartials;
|
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.tileEntity.behaviour.inventory.InvManipulationBehaviour;
|
||||||
import com.simibubi.create.foundation.utility.NBTHelper;
|
import com.simibubi.create.foundation.utility.NBTHelper;
|
||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
import com.simibubi.create.foundation.utility.VecHelper;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.block.ComposterBlock;
|
||||||
import net.minecraft.block.JukeboxBlock;
|
import net.minecraft.block.JukeboxBlock;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.MusicDiscItem;
|
import net.minecraft.item.MusicDiscItem;
|
||||||
|
@ -50,10 +46,14 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public abstract class ArmInteractionPoint {
|
public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
static enum Mode {
|
enum Mode {
|
||||||
DEPOSIT, TAKE
|
DEPOSIT, TAKE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,20 +65,21 @@ public abstract class ArmInteractionPoint {
|
||||||
private ArmAngleTarget cachedAngles;
|
private ArmAngleTarget cachedAngles;
|
||||||
|
|
||||||
private static ImmutableMap<ArmInteractionPoint, Supplier<ArmInteractionPoint>> POINTS =
|
private static ImmutableMap<ArmInteractionPoint, Supplier<ArmInteractionPoint>> POINTS =
|
||||||
ImmutableMap.<ArmInteractionPoint, Supplier<ArmInteractionPoint>>builder()
|
ImmutableMap.<ArmInteractionPoint, Supplier<ArmInteractionPoint>>builder()
|
||||||
.put(new Saw(), Saw::new)
|
.put(new Saw(), Saw::new)
|
||||||
.put(new Belt(), Belt::new)
|
.put(new Belt(), Belt::new)
|
||||||
.put(new Depot(), Depot::new)
|
.put(new Depot(), Depot::new)
|
||||||
.put(new Chute(), Chute::new)
|
.put(new Chute(), Chute::new)
|
||||||
.put(new Basin(), Basin::new)
|
.put(new Basin(), Basin::new)
|
||||||
.put(new Funnel(), Funnel::new)
|
.put(new Funnel(), Funnel::new)
|
||||||
.put(new Jukebox(), Jukebox::new)
|
.put(new Jukebox(), Jukebox::new)
|
||||||
.put(new Crafter(), Crafter::new)
|
.put(new Crafter(), Crafter::new)
|
||||||
.put(new Deployer(), Deployer::new)
|
.put(new Deployer(), Deployer::new)
|
||||||
.put(new Millstone(), Millstone::new)
|
.put(new Composter(), Composter::new)
|
||||||
.put(new BlazeBurner(), BlazeBurner::new)
|
.put(new Millstone(), Millstone::new)
|
||||||
.put(new CrushingWheels(), CrushingWheels::new)
|
.put(new BlazeBurner(), BlazeBurner::new)
|
||||||
.build();
|
.put(new CrushingWheels(), CrushingWheels::new)
|
||||||
|
.build();
|
||||||
|
|
||||||
public ArmInteractionPoint() {
|
public ArmInteractionPoint() {
|
||||||
cachedHandler = LazyOptional.empty();
|
cachedHandler = LazyOptional.empty();
|
||||||
|
@ -118,8 +119,8 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
ArmAngleTarget getTargetAngles(BlockPos armPos, boolean ceiling) {
|
ArmAngleTarget getTargetAngles(BlockPos armPos, boolean ceiling) {
|
||||||
if (cachedAngles == null)
|
if (cachedAngles == null)
|
||||||
cachedAngles =
|
cachedAngles = new ArmAngleTarget(armPos, getInteractionPositionVector(), getInteractionDirection(), ceiling);
|
||||||
new ArmAngleTarget(armPos, getInteractionPositionVector(), getInteractionDirection(), ceiling);
|
|
||||||
return cachedAngles;
|
return cachedAngles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,8 +167,7 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
for (ArmInteractionPoint armInteractionPoint : POINTS.keySet())
|
for (ArmInteractionPoint armInteractionPoint : POINTS.keySet())
|
||||||
if (armInteractionPoint.isValid(world, pos, state))
|
if (armInteractionPoint.isValid(world, pos, state))
|
||||||
point = POINTS.get(armInteractionPoint)
|
point = POINTS.get(armInteractionPoint).get();
|
||||||
.get();
|
|
||||||
|
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
point.state = state;
|
point.state = state;
|
||||||
|
@ -222,7 +222,7 @@ public abstract class ArmInteractionPoint {
|
||||||
@Override
|
@Override
|
||||||
boolean isValid(IBlockReader reader, BlockPos pos, BlockState state) {
|
boolean isValid(IBlockReader reader, BlockPos pos, BlockState state) {
|
||||||
return AllBlocks.MECHANICAL_SAW.has(state) && state.get(SawBlock.FACING) == Direction.UP
|
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 {
|
static class Deployer extends ArmInteractionPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -254,14 +273,12 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Direction getInteractionDirection() {
|
Direction getInteractionDirection() {
|
||||||
return state.get(DeployerBlock.FACING)
|
return state.get(DeployerBlock.FACING).getOpposite();
|
||||||
.getOpposite();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Vec3d getInteractionPositionVector() {
|
Vec3d getInteractionPositionVector() {
|
||||||
return super.getInteractionPositionVector()
|
return super.getInteractionPositionVector().add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.65f));
|
||||||
.add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.65f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -281,15 +298,13 @@ public abstract class ArmInteractionPoint {
|
||||||
@Override
|
@Override
|
||||||
ItemStack insert(World world, ItemStack stack, boolean simulate) {
|
ItemStack insert(World world, ItemStack stack, boolean simulate) {
|
||||||
ItemStack input = stack.copy();
|
ItemStack input = stack.copy();
|
||||||
if (!BlazeBurnerBlock.tryInsert(state, world, pos, input, false, true)
|
if (!BlazeBurnerBlock.tryInsert(state, world, pos, input, false, true).getResult().isEmpty()) {
|
||||||
.getResult()
|
|
||||||
.isEmpty()) {
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
ActionResult<ItemStack> res = BlazeBurnerBlock.tryInsert(state, world, pos, input, false, simulate);
|
ActionResult<ItemStack> res = BlazeBurnerBlock.tryInsert(state, world, pos, input, false, simulate);
|
||||||
return res.getType() == ActionResultType.SUCCESS
|
return res.getType() == ActionResultType.SUCCESS
|
||||||
? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - 1)
|
? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - 1)
|
||||||
: stack;
|
: stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -306,8 +321,7 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Direction getInteractionDirection() {
|
Direction getInteractionDirection() {
|
||||||
return state.get(MechanicalCrafterBlock.HORIZONTAL_FACING)
|
return state.get(MechanicalCrafterBlock.HORIZONTAL_FACING).getOpposite();
|
||||||
.getOpposite();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -325,8 +339,7 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Vec3d getInteractionPositionVector() {
|
Vec3d getInteractionPositionVector() {
|
||||||
return super.getInteractionPositionVector()
|
return super.getInteractionPositionVector().add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.5f));
|
||||||
.add(new Vec3d(getInteractionDirection().getDirectionVec()).scale(.5f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -361,8 +374,7 @@ public abstract class ArmInteractionPoint {
|
||||||
return stack;
|
return stack;
|
||||||
JukeboxBlock jukeboxBlock = (JukeboxBlock) state.getBlock();
|
JukeboxBlock jukeboxBlock = (JukeboxBlock) state.getBlock();
|
||||||
JukeboxTileEntity jukeboxTE = (JukeboxTileEntity) tileEntity;
|
JukeboxTileEntity jukeboxTE = (JukeboxTileEntity) tileEntity;
|
||||||
if (!jukeboxTE.getRecord()
|
if (!jukeboxTE.getRecord().isEmpty())
|
||||||
.isEmpty())
|
|
||||||
return stack;
|
return stack;
|
||||||
if (!(stack.getItem() instanceof MusicDiscItem))
|
if (!(stack.getItem() instanceof MusicDiscItem))
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -370,7 +382,7 @@ public abstract class ArmInteractionPoint {
|
||||||
ItemStack toInsert = remainder.split(1);
|
ItemStack toInsert = remainder.split(1);
|
||||||
if (!simulate && !world.isRemote) {
|
if (!simulate && !world.isRemote) {
|
||||||
jukeboxBlock.insertRecord(world, pos, state, toInsert);
|
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);
|
AllTriggers.triggerForNearbyPlayers(AllTriggers.MUSICAL_ARM, world, pos, 10);
|
||||||
}
|
}
|
||||||
return remainder;
|
return remainder;
|
||||||
|
@ -401,8 +413,7 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isValid(IBlockReader reader, BlockPos pos, BlockState state) {
|
boolean isValid(IBlockReader reader, BlockPos pos, BlockState state) {
|
||||||
return AllBlocks.BELT.has(state) && !(reader.getBlockState(pos.up())
|
return AllBlocks.BELT.has(state) && !(reader.getBlockState(pos.up()).getBlock() instanceof BeltTunnelBlock);
|
||||||
.getBlock() instanceof BeltTunnelBlock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,9 +429,7 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Vec3d getInteractionPositionVector() {
|
Vec3d getInteractionPositionVector() {
|
||||||
return VecHelper.getCenterOf(pos)
|
return VecHelper.getCenterOf(pos).add(new Vec3d(FunnelBlock.getFunnelFacing(state).getDirectionVec()).scale(-.15f));
|
||||||
.add(new Vec3d(FunnelBlock.getFunnelFacing(state)
|
|
||||||
.getDirectionVec()).scale(-.15f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -435,8 +444,7 @@ public abstract class ArmInteractionPoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Direction getInteractionDirection() {
|
Direction getInteractionDirection() {
|
||||||
return FunnelBlock.getFunnelFacing(state)
|
return FunnelBlock.getFunnelFacing(state).getOpposite();
|
||||||
.getOpposite();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue