mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
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)
|
for (int i = 0; i < itemStackHandler.getSlots(); i++) {
|
||||||
return;
|
if (itemStackHandler.getStackInSlot(i).isEmpty())
|
||||||
te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(itemStackHandler -> {
|
continue;
|
||||||
if (!(itemStackHandler instanceof IItemHandlerModifiable))
|
ItemEntity itemEntity = new ItemEntity(context.world, context.position.x, context.position.y, context.position.z, itemStackHandler.getStackInSlot(i));
|
||||||
return;
|
itemEntity.setMotion(facingVec.scale(.05));
|
||||||
for (int i = 0; i < itemStackHandler.getSlots(); i++) {
|
context.world.addEntity(itemEntity);
|
||||||
if (itemStackHandler.getStackInSlot(i).isEmpty())
|
itemStackHandler.setStackInSlot(i, ItemStack.EMPTY);
|
||||||
continue;
|
|
||||||
ItemEntity itemEntity = new ItemEntity(context.world, context.position.x, context.position.y, context.position.z, itemStackHandler.getStackInSlot(i));
|
|
||||||
itemEntity.setMotion(facingVec.scale(.05));
|
|
||||||
context.world.addEntity(itemEntity);
|
|
||||||
((IItemHandlerModifiable) itemStackHandler).setStackInSlot(i, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
te.write(context.tileData);
|
|
||||||
context.temporaryData = NO_OR_EMPTY_BASIN;
|
|
||||||
}
|
}
|
||||||
);
|
context.tileData.put(key, itemStackHandler.serializeNBT());
|
||||||
}
|
});
|
||||||
|
context.contraption.customRenderTEs.stream().filter(te -> te.getPos().equals(context.localPos) && te instanceof BasinTileEntity).forEach(te -> ((BasinTileEntity) te).readOnlyItems(context.tileData));
|
||||||
@Nullable
|
context.temporaryData = false; // did already dump, so can't any more
|
||||||
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