Simi Says
- reverted to temporary ItemStackHandlers to modify basins to avoid having weird TEs that should only exist on Clients present on the server
This commit is contained in:
parent
59f19adb89
commit
5cf4e02f45
2 changed files with 28 additions and 70 deletions
|
@ -1,25 +1,25 @@
|
||||||
package com.simibubi.create.content.contraptions.processing;
|
package com.simibubi.create.content.contraptions.processing;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
|
import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
|
||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
import com.simibubi.create.foundation.utility.VecHelper;
|
||||||
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.entity.item.ItemEntity;
|
import net.minecraft.entity.item.ItemEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.ItemStackHandler;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class BasinMovementBehaviour extends MovementBehaviour {
|
public class BasinMovementBehaviour extends MovementBehaviour {
|
||||||
private static final Object NO_OR_EMPTY_BASIN = new Object();
|
public Map<String, ItemStackHandler> getOrReadInventory(MovementContext context) {
|
||||||
|
Map<String, ItemStackHandler> map = new HashMap<>();
|
||||||
|
map.put("InputItems", new ItemStackHandler(9));
|
||||||
|
map.put("OutputItems", new ItemStackHandler(8));
|
||||||
|
map.forEach((s, h) -> h.deserializeNBT(context.tileData.getCompound(s)));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasSpecialMovementRenderer() {
|
public boolean hasSpecialMovementRenderer() {
|
||||||
|
@ -29,73 +29,27 @@ public class BasinMovementBehaviour extends MovementBehaviour {
|
||||||
@Override
|
@Override
|
||||||
public void tick(MovementContext context) {
|
public void tick(MovementContext context) {
|
||||||
super.tick(context);
|
super.tick(context);
|
||||||
if (context.temporaryData != NO_OR_EMPTY_BASIN) {
|
if (context.temporaryData == null || (boolean) context.temporaryData) {
|
||||||
Vec3d facingVec = VecHelper.rotate(new Vec3d(Direction.UP.getDirectionVec()), context.rotation.x, context.rotation.y, context.rotation.z);
|
Vec3d facingVec = VecHelper.rotate(new Vec3d(Direction.UP.getDirectionVec()), context.rotation.x, context.rotation.y, context.rotation.z);
|
||||||
facingVec.normalize();
|
facingVec.normalize();
|
||||||
if (Direction.getFacingFromVector(facingVec.x, facingVec.y, facingVec.z) == Direction.DOWN) {
|
if (Direction.getFacingFromVector(facingVec.x, facingVec.y, facingVec.z) == Direction.DOWN)
|
||||||
dump(context, facingVec);
|
dump(context, facingVec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void dump(MovementContext context, Vec3d facingVec) {
|
private void dump(MovementContext context, Vec3d facingVec) {
|
||||||
BasinTileEntity te = getOrCreate(context);
|
getOrReadInventory(context).forEach((key, itemStackHandler) -> {
|
||||||
if (te == null)
|
|
||||||
return;
|
|
||||||
te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(itemStackHandler -> {
|
|
||||||
if (!(itemStackHandler instanceof IItemHandlerModifiable))
|
|
||||||
return;
|
|
||||||
for (int i = 0; i < itemStackHandler.getSlots(); i++) {
|
for (int i = 0; i < itemStackHandler.getSlots(); i++) {
|
||||||
if (itemStackHandler.getStackInSlot(i).isEmpty())
|
if (itemStackHandler.getStackInSlot(i).isEmpty())
|
||||||
continue;
|
continue;
|
||||||
ItemEntity itemEntity = new ItemEntity(context.world, context.position.x, context.position.y, context.position.z, itemStackHandler.getStackInSlot(i));
|
ItemEntity itemEntity = new ItemEntity(context.world, context.position.x, context.position.y, context.position.z, itemStackHandler.getStackInSlot(i));
|
||||||
itemEntity.setMotion(facingVec.scale(.05));
|
itemEntity.setMotion(facingVec.scale(.05));
|
||||||
context.world.addEntity(itemEntity);
|
context.world.addEntity(itemEntity);
|
||||||
((IItemHandlerModifiable) itemStackHandler).setStackInSlot(i, ItemStack.EMPTY);
|
itemStackHandler.setStackInSlot(i, ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
te.write(context.tileData);
|
context.tileData.put(key, itemStackHandler.serializeNBT());
|
||||||
context.temporaryData = NO_OR_EMPTY_BASIN;
|
});
|
||||||
}
|
context.contraption.customRenderTEs.stream().filter(te -> te.getPos().equals(context.localPos) && te instanceof BasinTileEntity).forEach(te -> ((BasinTileEntity) te).readOnlyItems(context.tileData));
|
||||||
);
|
context.temporaryData = false; // did already dump, so can't any more
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private BasinTileEntity getOrCreate(MovementContext context) {
|
|
||||||
if (!(context.temporaryData instanceof BasinTileEntity || context.temporaryData == NO_OR_EMPTY_BASIN)) {
|
|
||||||
if (context.contraption.customRenderTEs.isEmpty()) {
|
|
||||||
// customRenderTEs are sometimes completely empty? Probably a server thing
|
|
||||||
context.tileData.putInt("x", context.localPos.getX());
|
|
||||||
context.tileData.putInt("y", context.localPos.getY());
|
|
||||||
context.tileData.putInt("z", context.localPos.getZ());
|
|
||||||
TileEntity te = TileEntity.create(context.tileData);
|
|
||||||
if (te == null) {
|
|
||||||
context.temporaryData = NO_OR_EMPTY_BASIN;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
te.setLocation(new WrappedWorld(context.world) {
|
|
||||||
@Override
|
|
||||||
public BlockState getBlockState(BlockPos pos) {
|
|
||||||
if (!pos.equals(te.getPos()))
|
|
||||||
return Blocks.AIR.getDefaultState();
|
|
||||||
return context.state;
|
|
||||||
}
|
|
||||||
}, te.getPos());
|
|
||||||
if (te instanceof KineticTileEntity)
|
|
||||||
((KineticTileEntity) te).setSpeed(0);
|
|
||||||
te.getBlockState();
|
|
||||||
context.temporaryData = te;
|
|
||||||
} else {
|
|
||||||
for (TileEntity te : context.contraption.customRenderTEs) {
|
|
||||||
if (te instanceof BasinTileEntity && te.getPos().equals(context.localPos)) {
|
|
||||||
context.temporaryData = te;
|
|
||||||
return ((BasinTileEntity) te);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context.temporaryData = NO_OR_EMPTY_BASIN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!(context.temporaryData instanceof BasinTileEntity))
|
|
||||||
return null;
|
|
||||||
return ((BasinTileEntity) context.temporaryData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,4 +167,8 @@ public class BasinTileEntity extends SmartTileEntity implements ITickableTileEnt
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void readOnlyItems(CompoundNBT compound) {
|
||||||
|
inputInventory.deserializeNBT(compound.getCompound("InputItems"));
|
||||||
|
outputInventory.deserializeNBT(compound.getCompound("OutputItems"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue