mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-18 16:02:19 +01:00
Cast with Caution
- Revisited every unchecked TileEntity cast - Redstone Links can now be toggled with a wrench - Redstong Links are now portable on contraptions - Schematicannon no longer inserts held schematics automatically - Saws no longer accept items when their speed is zero
This commit is contained in:
parent
f1057bf558
commit
810191aa89
97 changed files with 1254 additions and 932 deletions
|
@ -1,5 +1,8 @@
|
|||
package com.simibubi.create;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.simibubi.create.foundation.block.IHaveColorHandler;
|
||||
import com.simibubi.create.foundation.block.IHaveCustomBlockItem;
|
||||
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
|
||||
|
@ -45,7 +48,6 @@ import com.simibubi.create.modules.contraptions.redstone.ContactBlock;
|
|||
import com.simibubi.create.modules.contraptions.relays.advanced.SpeedControllerBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.advanced.sequencer.SequencedGearshiftBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTunnelBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.elementary.CogWheelBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.elementary.ShaftBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.encased.AdjustablePulleyBlock;
|
||||
|
@ -62,14 +64,15 @@ import com.simibubi.create.modules.curiosities.symmetry.block.TriplePlaneSymmetr
|
|||
import com.simibubi.create.modules.gardens.CocoaLogBlock;
|
||||
import com.simibubi.create.modules.logistics.block.RedstoneLinkBlock;
|
||||
import com.simibubi.create.modules.logistics.block.StockswitchBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.BeltObserverBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.FunnelBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.observer.BeltObserverBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.tunnel.BeltTunnelBlock;
|
||||
import com.simibubi.create.modules.logistics.block.diodes.FlexpeaterBlock;
|
||||
import com.simibubi.create.modules.logistics.block.diodes.LatchBlock;
|
||||
import com.simibubi.create.modules.logistics.block.diodes.PulseRepeaterBlock;
|
||||
import com.simibubi.create.modules.logistics.block.diodes.ToggleLatchBlock;
|
||||
import com.simibubi.create.modules.logistics.block.extractor.ExtractorBlock;
|
||||
import com.simibubi.create.modules.logistics.block.extractor.LinkedExtractorBlock;
|
||||
import com.simibubi.create.modules.logistics.block.funnel.FunnelBlock;
|
||||
import com.simibubi.create.modules.logistics.block.inventories.FlexcrateBlock;
|
||||
import com.simibubi.create.modules.logistics.block.transposer.LinkedTransposerBlock;
|
||||
import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock;
|
||||
|
@ -107,9 +110,6 @@ import net.minecraftforge.common.ToolType;
|
|||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public enum AllBlocks {
|
||||
|
||||
__SCHEMATICS__(),
|
||||
|
|
|
@ -55,8 +55,6 @@ public enum AllContainers {
|
|||
bind(SCHEMATIC_TABLE, SchematicTableScreen::new);
|
||||
bind(SCHEMATICANNON, SchematicannonScreen::new);
|
||||
bind(FLEXCRATE, FlexcrateScreen::new);
|
||||
// bind(LOGISTICAL_INDEX, LogisticalIndexScreen::new);
|
||||
// bind(LOGISTICAL_CONTROLLER, LogisticalInventoryControllerScreen::new);
|
||||
bind(FILTER, FilterScreen::new);
|
||||
bind(ATTRIBUTE_FILTER, AttributeFilterScreen::new);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.simibubi.create.foundation.utility.data.ITaggable;
|
|||
import com.simibubi.create.modules.IModule;
|
||||
import com.simibubi.create.modules.contraptions.GogglesItem;
|
||||
import com.simibubi.create.modules.contraptions.WrenchItem;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltConnectorItem;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.item.BeltConnectorItem;
|
||||
import com.simibubi.create.modules.contraptions.relays.gearbox.VerticalGearboxItem;
|
||||
import com.simibubi.create.modules.curiosities.ChromaticCompoundCubeItem;
|
||||
import com.simibubi.create.modules.curiosities.RefinedRadianceItem;
|
||||
|
@ -42,8 +42,8 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.Item.Properties;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Rarity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.item.SwordItem;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
|
|
|
@ -55,8 +55,6 @@ import com.simibubi.create.modules.contraptions.relays.advanced.SpeedControllerT
|
|||
import com.simibubi.create.modules.contraptions.relays.advanced.sequencer.SequencedGearshiftTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntityRenderer;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTunnelTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTunnelTileEntityRenderer;
|
||||
import com.simibubi.create.modules.contraptions.relays.elementary.ShaftTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.encased.AdjustablePulleyTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.encased.ClutchTileEntity;
|
||||
|
@ -73,14 +71,16 @@ import com.simibubi.create.modules.contraptions.relays.gearbox.GearshiftTileEnti
|
|||
import com.simibubi.create.modules.curiosities.partialWindows.WindowInABlockTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.RedstoneLinkTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.StockswitchTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.BeltObserverTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.BeltObserverTileEntityRenderer;
|
||||
import com.simibubi.create.modules.logistics.block.belts.FunnelTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.observer.BeltObserverTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.observer.BeltObserverTileEntityRenderer;
|
||||
import com.simibubi.create.modules.logistics.block.belts.tunnel.BeltTunnelTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.tunnel.BeltTunnelTileEntityRenderer;
|
||||
import com.simibubi.create.modules.logistics.block.diodes.FlexPulsepeaterTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.diodes.FlexpeaterTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.diodes.FlexpeaterTileEntityRenderer;
|
||||
import com.simibubi.create.modules.logistics.block.extractor.ExtractorTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.extractor.LinkedExtractorTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.funnel.FunnelTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.inventories.FlexcrateTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.transposer.LinkedTransposerTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.transposer.TransposerTileEntity;
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.simibubi.create.modules.contraptions.KineticDebugger;
|
|||
import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.ChassisRangeDisplay;
|
||||
import com.simibubi.create.modules.contraptions.components.turntable.TurntableHandler;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltConnectorItemHandler;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.item.BeltConnectorHandler;
|
||||
import com.simibubi.create.modules.curiosities.zapper.terrainzapper.TerrainZapperRenderHandler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -60,7 +60,7 @@ public class ClientEvents {
|
|||
|
||||
public static void onGameTick() {
|
||||
CreateClient.gameTick();
|
||||
BeltConnectorItemHandler.gameTick();
|
||||
BeltConnectorHandler.gameTick();
|
||||
TerrainZapperRenderHandler.tick();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,10 @@
|
|||
package com.simibubi.create;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.simibubi.create.config.AllConfigs;
|
||||
import com.simibubi.create.modules.curiosities.partialWindows.WindowInABlockTileEntity;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FourWayBlock;
|
||||
import net.minecraft.block.WallBlock;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.event.TickEvent.Phase;
|
||||
import net.minecraftforge.event.TickEvent.ServerTickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
@ -59,60 +42,4 @@ public class Events {
|
|||
Create.torquePropagator.onUnloadWorld(world);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRightClickBlock(RightClickBlock event) {
|
||||
if (event.getUseItem() == Result.DENY)
|
||||
return;
|
||||
if (event.getEntityLiving().isSneaking())
|
||||
return;
|
||||
if (!event.getPlayer().isAllowEdit())
|
||||
return;
|
||||
if (!AllConfigs.SERVER.curiosities.allowGlassPanesInPartialBlocks.get())
|
||||
return;
|
||||
|
||||
ItemStack stack = event.getItemStack();
|
||||
if (stack.isEmpty())
|
||||
return;
|
||||
if (!(stack.getItem() instanceof BlockItem))
|
||||
return;
|
||||
BlockItem item = (BlockItem) stack.getItem();
|
||||
if (!item.isIn(Tags.Items.GLASS_PANES)
|
||||
&& (item.getBlock() == null || !item.getBlock().isIn(Tags.Blocks.GLASS_PANES)))
|
||||
return;
|
||||
|
||||
BlockPos pos = event.getPos();
|
||||
World world = event.getWorld();
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (!AllBlockTags.WINDOWABLE.matches(blockState))
|
||||
return;
|
||||
if (AllBlocks.WINDOW_IN_A_BLOCK.typeOf(blockState))
|
||||
return;
|
||||
|
||||
BlockState defaultState = AllBlocks.WINDOW_IN_A_BLOCK.get().getDefaultState();
|
||||
world.setBlockState(pos, defaultState);
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te != null && te instanceof WindowInABlockTileEntity) {
|
||||
WindowInABlockTileEntity wte = (WindowInABlockTileEntity) te;
|
||||
wte.setWindowBlock(item.getBlock().getDefaultState());
|
||||
wte.updateWindowConnections();
|
||||
|
||||
if (blockState.getBlock() instanceof FourWayBlock) {
|
||||
for (BooleanProperty side : Arrays.asList(FourWayBlock.EAST, FourWayBlock.NORTH, FourWayBlock.SOUTH,
|
||||
FourWayBlock.WEST))
|
||||
blockState = blockState.with(side, false);
|
||||
}
|
||||
if (blockState.getBlock() instanceof WallBlock)
|
||||
blockState = blockState.with(WallBlock.UP, true);
|
||||
|
||||
wte.setPartialBlock(blockState);
|
||||
wte.requestModelDataUpdate();
|
||||
|
||||
if (!event.getPlayer().isCreative())
|
||||
stack.shrink(1);
|
||||
event.getPlayer().swingArm(event.getHand());
|
||||
}
|
||||
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simibubi.create.config;
|
|||
public class CCommon extends ConfigBase {
|
||||
|
||||
public CWorldGen worldGen = nested(0, CWorldGen::new, Comments.worldGen);
|
||||
public ConfigBool logTeErrors = b(false, "logTeErrors", Comments.logTeErrors);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
@ -11,6 +12,7 @@ public class CCommon extends ConfigBase {
|
|||
|
||||
private static class Comments {
|
||||
static String worldGen = "Modify Create's impact on your terrain";
|
||||
static String logTeErrors = "Forward caught TileEntityExceptions to the log at debug level.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
100
src/main/java/com/simibubi/create/foundation/block/ITE.java
Normal file
100
src/main/java/com/simibubi/create/foundation/block/ITE.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package com.simibubi.create.foundation.block;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.config.AllConfigs;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.dimension.Dimension;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
public interface ITE<T extends TileEntity> {
|
||||
|
||||
Class<T> getTileEntityClass();
|
||||
|
||||
default void withTileEntityDo(IBlockReader world, BlockPos pos, Consumer<T> action) {
|
||||
try {
|
||||
action.accept(getTileEntity(world, pos));
|
||||
} catch (TileEntityException e) {}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default T getTileEntity(IBlockReader worldIn, BlockPos pos) throws TileEntityException {
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
Class<T> expectedClass = getTileEntityClass();
|
||||
|
||||
IWorld world = null;
|
||||
if (worldIn instanceof IWorld)
|
||||
world = (IWorld) worldIn;
|
||||
|
||||
if (tileEntity == null)
|
||||
throw new MissingTileEntityException(world, pos, expectedClass);
|
||||
if (!expectedClass.isInstance(tileEntity))
|
||||
throw new InvalidTileEntityException(world, pos, expectedClass, tileEntity.getClass());
|
||||
|
||||
return (T) tileEntity;
|
||||
}
|
||||
|
||||
static class TileEntityException extends Throwable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TileEntityException(IWorld world, BlockPos pos, Class<?> teClass) {
|
||||
super(makeBaseMessage(world, pos, teClass));
|
||||
}
|
||||
|
||||
public TileEntityException(String message) {
|
||||
super(message);
|
||||
report(this);
|
||||
}
|
||||
|
||||
static String makeBaseMessage(IWorld world, BlockPos pos, Class<?> expectedTeClass) {
|
||||
return String.format("[%s] @(%d, %d, %d), expecting a %s", getDimensionName(world), pos.getX(), pos.getY(),
|
||||
pos.getZ(), expectedTeClass.getSimpleName());
|
||||
}
|
||||
|
||||
static String getDimensionName(IWorld world) {
|
||||
String notAvailable = "Dim N/A";
|
||||
if (world == null)
|
||||
return notAvailable;
|
||||
Dimension dimension = world.getDimension();
|
||||
if (dimension == null)
|
||||
return notAvailable;
|
||||
DimensionType type = dimension.getType();
|
||||
if (type == null)
|
||||
return notAvailable;
|
||||
ResourceLocation registryName = type.getRegistryName();
|
||||
if (registryName == null)
|
||||
return notAvailable;
|
||||
return registryName.toString();
|
||||
}
|
||||
}
|
||||
|
||||
static class MissingTileEntityException extends TileEntityException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MissingTileEntityException(IWorld world, BlockPos pos, Class<?> teClass) {
|
||||
super("Missing TileEntity: " + makeBaseMessage(world, pos, teClass));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class InvalidTileEntityException extends TileEntityException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidTileEntityException(IWorld world, BlockPos pos, Class<?> expectedTeClass, Class<?> foundTeClass) {
|
||||
super("Wrong TileEntity: " + makeBaseMessage(world, pos, expectedTeClass) + ", found "
|
||||
+ foundTeClass.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
static void report(TileEntityException e) {
|
||||
if (AllConfigs.COMMON.logTeErrors.get())
|
||||
Create.logger.debug("TileEntityException thrown!", e);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,13 +7,15 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.world.IWorld;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
public interface IWithContainerTileEntity<T extends TileEntity & IWithContainer<T, ?>> extends IWithTileEntity<T> {
|
||||
public interface IWithContainerTileEntity<T extends TileEntity & IWithContainer<T, ?>> extends ITE<T> {
|
||||
|
||||
default void open(IWorld world, BlockPos pos, PlayerEntity player) {
|
||||
T te = getTileEntity(world, pos);
|
||||
if (te == null || world.isRemote())
|
||||
if (world.isRemote())
|
||||
return;
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
|
||||
try {
|
||||
T te = getTileEntity(world, pos);
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
|
||||
} catch (TileEntityException e) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package com.simibubi.create.foundation.block;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public interface IWithTileEntity<T extends TileEntity> {
|
||||
|
||||
default void withTileEntityDo(IBlockReader world, BlockPos pos, Consumer<T> action) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T te = (T) world.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return;
|
||||
action.accept(te);
|
||||
}
|
||||
|
||||
default T getTileEntity(IBlockReader world, BlockPos pos) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T te = (T) world.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return null;
|
||||
return te;
|
||||
}
|
||||
|
||||
}
|
|
@ -12,15 +12,23 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
|
||||
import com.simibubi.create.config.AllConfigs;
|
||||
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
public class ItemHelper {
|
||||
|
||||
public static void dropContents(World world, BlockPos pos, IItemHandler inv) {
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++)
|
||||
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), inv.getStackInSlot(slot));
|
||||
}
|
||||
|
||||
public static List<ItemStack> multipliedOutput(ItemStack in, ItemStack out) {
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
ItemStack result = out.copy();
|
||||
|
|
|
@ -15,8 +15,8 @@ import com.simibubi.create.modules.IModule;
|
|||
import com.simibubi.create.modules.contraptions.base.IRotate;
|
||||
import com.simibubi.create.modules.contraptions.components.flywheel.engine.EngineBlock;
|
||||
import com.simibubi.create.modules.curiosities.tools.AllToolTiers;
|
||||
|
||||
import com.simibubi.create.modules.curiosities.tools.SandPaperItem;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package com.simibubi.create.foundation.utility;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class Iterate {
|
||||
|
||||
|
@ -18,4 +22,9 @@ public class Iterate {
|
|||
return directions;
|
||||
}
|
||||
|
||||
public static List<BlockPos> hereAndBelow(BlockPos pos) {
|
||||
return Arrays.asList(pos, pos.down());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package com.simibubi.create.foundation.utility.data;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.data.BlockTagsProvider;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
|
@ -8,10 +13,6 @@ import net.minecraft.tags.BlockTags;
|
|||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AllBlocksTagProvider extends BlockTagsProvider {
|
||||
|
||||
static Map<ResourceLocation, BlockTags.Wrapper> createdTags;
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
package com.simibubi.create.modules.contraptions;
|
||||
|
||||
import com.simibubi.create.foundation.utility.VoxelShaper;
|
||||
import com.simibubi.create.modules.contraptions.base.*;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.GeneratingKineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.RotatedPillarKineticBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
|
|
@ -60,7 +60,7 @@ public class KineticDebugger {
|
|||
|
||||
BlockRayTraceResult ray = (BlockRayTraceResult) obj;
|
||||
TileEntity te = world.getTileEntity(ray.getPos());
|
||||
if (te == null || !(te instanceof KineticTileEntity))
|
||||
if (!(te instanceof KineticTileEntity))
|
||||
return null;
|
||||
|
||||
return (KineticTileEntity) te;
|
||||
|
|
|
@ -327,7 +327,10 @@ public class RotationPropagator {
|
|||
|
||||
while (!frontier.isEmpty()) {
|
||||
final BlockPos pos = frontier.remove(0);
|
||||
final KineticTileEntity currentTE = (KineticTileEntity) world.getTileEntity(pos);
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof KineticTileEntity))
|
||||
continue;
|
||||
final KineticTileEntity currentTE = (KineticTileEntity) tileEntity;
|
||||
|
||||
currentTE.removeSource();
|
||||
currentTE.sendData();
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.simibubi.create.modules.contraptions.KineticNetwork;
|
|||
import com.simibubi.create.modules.contraptions.base.IRotate.SpeedLevel;
|
||||
import com.simibubi.create.modules.contraptions.goggle.IHaveGoggleInformation;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
@ -33,7 +34,10 @@ public abstract class GeneratingKineticTileEntity extends KineticTileEntity {
|
|||
@Override
|
||||
public void setSource(BlockPos source) {
|
||||
super.setSource(source);
|
||||
KineticTileEntity sourceTe = (KineticTileEntity) world.getTileEntity(source);
|
||||
TileEntity tileEntity = world.getTileEntity(source);
|
||||
if (!(tileEntity instanceof KineticTileEntity))
|
||||
return;
|
||||
KineticTileEntity sourceTe = (KineticTileEntity) tileEntity;
|
||||
if (reActivateSource && sourceTe != null && Math.abs(sourceTe.getSpeed()) >= Math.abs(getGeneratedSpeed()))
|
||||
reActivateSource = false;
|
||||
}
|
||||
|
|
|
@ -79,30 +79,19 @@ public abstract class KineticBlock extends Block implements IRotate {
|
|||
@Override
|
||||
public abstract TileEntity createTileEntity(BlockState state, IBlockReader world);
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
|
||||
if (isMoving) {
|
||||
KineticTileEntity tileEntity = (KineticTileEntity) worldIn.getTileEntity(pos);
|
||||
if (tileEntity == null)
|
||||
return;
|
||||
if (worldIn.isRemote())
|
||||
return;
|
||||
tileEntity.network = null;
|
||||
tileEntity.source = null;
|
||||
tileEntity.speed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void updateNeighbors(BlockState stateIn, IWorld worldIn, BlockPos pos, int flags) {
|
||||
super.updateNeighbors(stateIn, worldIn, pos, flags);
|
||||
KineticTileEntity tileEntity = (KineticTileEntity) worldIn.getTileEntity(pos);
|
||||
if (tileEntity == null)
|
||||
return;
|
||||
if (worldIn.isRemote())
|
||||
return;
|
||||
RotationPropagator.handleAdded(worldIn.getWorld(), pos, tileEntity);
|
||||
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof KineticTileEntity))
|
||||
return;
|
||||
|
||||
KineticTileEntity kte = (KineticTileEntity) tileEntity;
|
||||
RotationPropagator.handleAdded(worldIn.getWorld(), pos, kte);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,12 +108,13 @@ public abstract class KineticBlock extends Block implements IRotate {
|
|||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (tileEntity == null || !(tileEntity instanceof KineticTileEntity))
|
||||
return;
|
||||
if (worldIn.isRemote)
|
||||
return;
|
||||
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof KineticTileEntity))
|
||||
return;
|
||||
|
||||
KineticTileEntity kte = (KineticTileEntity) tileEntity;
|
||||
kte.effects.queueRotationIndicators();
|
||||
}
|
||||
|
|
|
@ -104,7 +104,9 @@ public abstract class KineticTileEntity extends SmartTileEntity
|
|||
if (!world.isBlockPresent(source))
|
||||
return;
|
||||
|
||||
KineticTileEntity sourceTe = (KineticTileEntity) world.getTileEntity(source);
|
||||
TileEntity tileEntity = world.getTileEntity(source);
|
||||
KineticTileEntity sourceTe =
|
||||
tileEntity instanceof KineticTileEntity ? (KineticTileEntity) tileEntity : null;
|
||||
if (sourceTe == null || sourceTe.speed == 0) {
|
||||
removeSource();
|
||||
detachKinetics();
|
||||
|
@ -266,12 +268,13 @@ public abstract class KineticTileEntity extends SmartTileEntity
|
|||
if (world == null || world.isRemote)
|
||||
return;
|
||||
|
||||
KineticTileEntity sourceTe = (KineticTileEntity) world.getTileEntity(source);
|
||||
if (sourceTe == null) {
|
||||
TileEntity tileEntity = world.getTileEntity(source);
|
||||
if (!(tileEntity instanceof KineticTileEntity)) {
|
||||
removeSource();
|
||||
return;
|
||||
}
|
||||
|
||||
KineticTileEntity sourceTe = (KineticTileEntity) tileEntity;
|
||||
setNetwork(sourceTe.network);
|
||||
}
|
||||
|
||||
|
@ -336,9 +339,11 @@ public abstract class KineticTileEntity extends SmartTileEntity
|
|||
public static void switchToBlockState(World world, BlockPos pos, BlockState state) {
|
||||
if (world.isRemote)
|
||||
return;
|
||||
|
||||
TileEntity tileEntityIn = world.getTileEntity(pos);
|
||||
if (!(tileEntityIn instanceof KineticTileEntity))
|
||||
return;
|
||||
|
||||
KineticTileEntity tileEntity = (KineticTileEntity) tileEntityIn;
|
||||
if (tileEntity.hasNetwork())
|
||||
tileEntity.getOrCreateNetwork().remove(tileEntity);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.simibubi.create.modules.contraptions.components.actors;
|
||||
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock;
|
||||
|
@ -25,7 +25,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class DrillBlock extends DirectionalKineticBlock implements IPortableBlock, IWithTileEntity<DrillTileEntity> {
|
||||
public class DrillBlock extends DirectionalKineticBlock implements IPortableBlock, ITE<DrillTileEntity> {
|
||||
|
||||
public static MovementBehaviour MOVEMENT = new DrillMovementBehaviour();
|
||||
public static DamageSource damageSourceDrill = new DamageSource("create.drill").setDamageBypassesArmor();
|
||||
|
@ -93,4 +93,9 @@ public class DrillBlock extends DirectionalKineticBlock implements IPortableBloc
|
|||
return MOVEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DrillTileEntity> getTileEntityClass() {
|
||||
return DrillTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import com.simibubi.create.AllBlocks;
|
|||
import com.simibubi.create.modules.contraptions.components.actors.HarvesterBlock;
|
||||
import com.simibubi.create.modules.contraptions.components.actors.PortableStorageInterfaceBlock;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.chassis.AbstractChassisBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.FunnelBlock;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.extractor.ExtractorBlock;
|
||||
import com.simibubi.create.modules.logistics.block.funnel.FunnelBlock;
|
||||
import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock;
|
||||
|
||||
import net.minecraft.block.AbstractPressurePlateBlock;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simibubi.create.modules.contraptions.components.contraptions.bearing;
|
||||
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.Direction;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.simibubi.create.modules.contraptions.components.contraptions.bearing;
|
||||
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
@ -11,7 +11,7 @@ import net.minecraft.util.math.BlockRayTraceResult;
|
|||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ClockworkBearingBlock extends BearingBlock implements IWithTileEntity<ClockworkBearingTileEntity> {
|
||||
public class ClockworkBearingBlock extends BearingBlock implements ITE<ClockworkBearingTileEntity> {
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
|
@ -40,4 +40,9 @@ public class ClockworkBearingBlock extends BearingBlock implements IWithTileEnti
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ClockworkBearingTileEntity> getTileEntityClass() {
|
||||
return ClockworkBearingTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.simibubi.create.modules.contraptions.components.contraptions.bearing;
|
||||
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -12,7 +12,7 @@ import net.minecraft.util.math.BlockRayTraceResult;
|
|||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class MechanicalBearingBlock extends BearingBlock implements IWithTileEntity<MechanicalBearingTileEntity> {
|
||||
public class MechanicalBearingBlock extends BearingBlock implements ITE<MechanicalBearingTileEntity> {
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
|
@ -55,4 +55,9 @@ public class MechanicalBearingBlock extends BearingBlock implements IWithTileEnt
|
|||
withTileEntityDo(worldIn, pos, MechanicalBearingTileEntity::neighbourChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MechanicalBearingTileEntity> getTileEntityClass() {
|
||||
return MechanicalBearingTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,11 @@ package com.simibubi.create.modules.contraptions.components.contraptions.piston;
|
|||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllSoundEvents;
|
||||
import com.simibubi.create.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -17,7 +18,11 @@ import net.minecraft.state.EnumProperty;
|
|||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
@ -29,7 +34,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.Tags;
|
||||
|
||||
public class MechanicalPistonBlock extends DirectionalAxisKineticBlock
|
||||
implements IWithTileEntity<MechanicalPistonTileEntity> {
|
||||
implements ITE<MechanicalPistonTileEntity> {
|
||||
|
||||
public static final EnumProperty<PistonState> STATE = EnumProperty.create("state", PistonState.class);
|
||||
protected boolean isSticky;
|
||||
|
@ -166,4 +171,9 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock
|
|||
return VoxelShapes.fullCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MechanicalPistonTileEntity> getTileEntityClass() {
|
||||
return MechanicalPistonTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.pulley;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalAxisKineticBlock;
|
||||
|
||||
|
@ -23,7 +23,7 @@ import net.minecraft.util.math.shapes.VoxelShape;
|
|||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PulleyBlock extends HorizontalAxisKineticBlock implements IWithTileEntity<PulleyTileEntity> {
|
||||
public class PulleyBlock extends HorizontalAxisKineticBlock implements ITE<PulleyTileEntity> {
|
||||
|
||||
public static EnumProperty<Axis> HORIZONTAL_AXIS = BlockStateProperties.HORIZONTAL_AXIS;
|
||||
|
||||
|
@ -130,4 +130,9 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements IWithTile
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<PulleyTileEntity> getTileEntityClass() {
|
||||
return PulleyTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simibubi.create.modules.contraptions.components.crafter;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour;
|
||||
import com.simibubi.create.foundation.block.connected.IHaveConnectedTextures;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
|
@ -42,7 +42,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
|||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class MechanicalCrafterBlock extends HorizontalKineticBlock
|
||||
implements IWithTileEntity<MechanicalCrafterTileEntity>, IHaveConnectedTextures {
|
||||
implements ITE<MechanicalCrafterTileEntity>, IHaveConnectedTextures {
|
||||
|
||||
public static final EnumProperty<Pointing> POINTING = EnumProperty.create("pointing", Pointing.class);
|
||||
|
||||
|
@ -291,4 +291,9 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock
|
|||
return new InputCTBehaviour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MechanicalCrafterTileEntity> getTileEntityClass() {
|
||||
return MechanicalCrafterTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -309,7 +309,7 @@ public class MechanicalCrafterTileEntity extends KineticTileEntity {
|
|||
if (!AllBlocks.BELT.typeOf(world.getBlockState(targetPos)))
|
||||
return false;
|
||||
TileEntity te = world.getTileEntity(targetPos);
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
if (!(te instanceof BeltTileEntity))
|
||||
return false;
|
||||
return ((KineticTileEntity) te).getSpeed() != 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.simibubi.create.modules.contraptions.components.crank;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class HandCrankBlock extends DirectionalKineticBlock implements IWithTileEntity<HandCrankTileEntity> {
|
||||
public class HandCrankBlock extends DirectionalKineticBlock implements ITE<HandCrankTileEntity> {
|
||||
|
||||
public HandCrankBlock() {
|
||||
super(Properties.from(AllBlocks.COGWHEEL.get()));
|
||||
|
@ -95,4 +95,9 @@ public class HandCrankBlock extends DirectionalKineticBlock implements IWithTile
|
|||
return state.get(FACING).getAxis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<HandCrankTileEntity> getTileEntityClass() {
|
||||
return HandCrankTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package com.simibubi.create.modules.contraptions.components.crusher;
|
|||
import static com.simibubi.create.modules.contraptions.components.crusher.CrushingWheelControllerBlock.VALID;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.RotatedPillarKineticBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -21,7 +21,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CrushingWheelBlock extends RotatedPillarKineticBlock {
|
||||
public class CrushingWheelBlock extends RotatedPillarKineticBlock implements ITE<CrushingWheelTileEntity> {
|
||||
|
||||
public CrushingWheelBlock() {
|
||||
super(Properties.from(Blocks.DIORITE));
|
||||
|
@ -75,15 +75,22 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock {
|
|||
BlockState otherState = world.getBlockState(otherWheelPos);
|
||||
if (AllBlocks.CRUSHING_WHEEL.typeOf(otherState)) {
|
||||
controllerShouldExist = true;
|
||||
KineticTileEntity te = (KineticTileEntity) world.getTileEntity(pos);
|
||||
KineticTileEntity otherTe = (KineticTileEntity) world.getTileEntity(otherWheelPos);
|
||||
if (te != null && otherTe != null && (te.getSpeed() > 0) != (otherTe.getSpeed() > 0)
|
||||
&& te.getSpeed() != 0) {
|
||||
float signum = Math.signum(te.getSpeed()) * (state.get(AXIS) == Axis.X ? -1 : 1);
|
||||
controllerShouldBeValid = facing.getAxisDirection().getOffset() != signum;
|
||||
}
|
||||
if (otherState.get(AXIS) != state.get(AXIS))
|
||||
|
||||
try {
|
||||
CrushingWheelTileEntity te = getTileEntity(world, pos);
|
||||
CrushingWheelTileEntity otherTe = getTileEntity(world, otherWheelPos);
|
||||
|
||||
if (te != null && otherTe != null && (te.getSpeed() > 0) != (otherTe.getSpeed() > 0)
|
||||
&& te.getSpeed() != 0) {
|
||||
float signum = Math.signum(te.getSpeed()) * (state.get(AXIS) == Axis.X ? -1 : 1);
|
||||
controllerShouldBeValid = facing.getAxisDirection().getOffset() != signum;
|
||||
}
|
||||
if (otherState.get(AXIS) != state.get(AXIS))
|
||||
controllerShouldExist = false;
|
||||
|
||||
} catch (TileEntityException e) {
|
||||
controllerShouldExist = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!controllerShouldExist) {
|
||||
|
@ -108,24 +115,25 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock {
|
|||
|
||||
@Override
|
||||
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
|
||||
KineticTileEntity te = (KineticTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return;
|
||||
if (entityIn.posY < pos.getY() + 1.25f || !entityIn.onGround)
|
||||
return;
|
||||
try {
|
||||
CrushingWheelTileEntity te = getTileEntity(worldIn, pos);
|
||||
if (entityIn.posY < pos.getY() + 1.25f || !entityIn.onGround)
|
||||
return;
|
||||
|
||||
double x = 0;
|
||||
double z = 0;
|
||||
double x = 0;
|
||||
double z = 0;
|
||||
|
||||
if (state.get(AXIS) == Axis.X) {
|
||||
z = te.getSpeed() / 20f;
|
||||
x += (pos.getX() + .5f - entityIn.posX) * .1f;
|
||||
}
|
||||
if (state.get(AXIS) == Axis.Z) {
|
||||
x = te.getSpeed() / -20f;
|
||||
z += (pos.getZ() + .5f - entityIn.posZ) * .1f;
|
||||
}
|
||||
entityIn.setMotion(entityIn.getMotion().add(x, 0, z));
|
||||
if (state.get(AXIS) == Axis.X) {
|
||||
z = te.getSpeed() / 20f;
|
||||
x += (pos.getX() + .5f - entityIn.posX) * .1f;
|
||||
}
|
||||
if (state.get(AXIS) == Axis.Z) {
|
||||
x = te.getSpeed() / -20f;
|
||||
z += (pos.getZ() + .5f - entityIn.posZ) * .1f;
|
||||
}
|
||||
entityIn.setMotion(entityIn.getMotion().add(x, 0, z));
|
||||
|
||||
} catch (TileEntityException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,4 +178,9 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock {
|
|||
return 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<CrushingWheelTileEntity> getTileEntityClass() {
|
||||
return CrushingWheelTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.util.Random;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.item.ItemHelper;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -12,7 +14,6 @@ import net.minecraft.block.Blocks;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
|
@ -33,7 +34,8 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CrushingWheelControllerBlock extends Block implements IHaveNoBlockItem {
|
||||
public class CrushingWheelControllerBlock extends Block
|
||||
implements IHaveNoBlockItem, ITE<CrushingWheelControllerTileEntity> {
|
||||
|
||||
public static final BooleanProperty VALID = BooleanProperty.create("valid");
|
||||
|
||||
|
@ -65,11 +67,10 @@ public class CrushingWheelControllerBlock extends Block implements IHaveNoBlockI
|
|||
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
|
||||
if (!state.get(VALID) || CrushingWheelControllerTileEntity.isFrozen())
|
||||
return;
|
||||
CrushingWheelControllerTileEntity te = (CrushingWheelControllerTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return;
|
||||
if (te.processingEntity == entityIn)
|
||||
entityIn.setMotionMultiplier(state, new Vec3d(0.25D, (double) 0.05F, 0.25D));
|
||||
withTileEntityDo(worldIn, pos, te -> {
|
||||
if (te.processingEntity == entityIn)
|
||||
entityIn.setMotionMultiplier(state, new Vec3d(0.25D, (double) 0.05F, 0.25D));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,25 +78,23 @@ public class CrushingWheelControllerBlock extends Block implements IHaveNoBlockI
|
|||
super.onLanded(worldIn, entityIn);
|
||||
if (CrushingWheelControllerTileEntity.isFrozen())
|
||||
return;
|
||||
TileEntity tileEntity = worldIn.getTileEntity(entityIn.getPosition().down());
|
||||
if (tileEntity == null)
|
||||
return;
|
||||
if (!(tileEntity instanceof CrushingWheelControllerTileEntity))
|
||||
return;
|
||||
CrushingWheelControllerTileEntity te = (CrushingWheelControllerTileEntity) tileEntity;
|
||||
if (te.crushingspeed == 0)
|
||||
return;
|
||||
if (entityIn instanceof ItemEntity)
|
||||
((ItemEntity) entityIn).setPickupDelay(10);
|
||||
if (te.isOccupied())
|
||||
return;
|
||||
boolean isPlayer = entityIn instanceof PlayerEntity;
|
||||
if (isPlayer && ((PlayerEntity) entityIn).isCreative())
|
||||
return;
|
||||
if (isPlayer && entityIn.world.getDifficulty() == Difficulty.PEACEFUL)
|
||||
return;
|
||||
|
||||
te.startCrushing(entityIn);
|
||||
try {
|
||||
CrushingWheelControllerTileEntity te = getTileEntity(worldIn, entityIn.getPosition().down());
|
||||
if (te.crushingspeed == 0)
|
||||
return;
|
||||
if (entityIn instanceof ItemEntity)
|
||||
((ItemEntity) entityIn).setPickupDelay(10);
|
||||
if (te.isOccupied())
|
||||
return;
|
||||
boolean isPlayer = entityIn instanceof PlayerEntity;
|
||||
if (isPlayer && ((PlayerEntity) entityIn).isCreative())
|
||||
return;
|
||||
if (isPlayer && entityIn.world.getDifficulty() == Difficulty.PEACEFUL)
|
||||
return;
|
||||
|
||||
te.startCrushing(entityIn);
|
||||
} catch (TileEntityException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,32 +117,29 @@ public class CrushingWheelControllerBlock extends Block implements IHaveNoBlockI
|
|||
}
|
||||
|
||||
public void updateSpeed(BlockState state, World world, BlockPos pos) {
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (tileEntity == null || !(tileEntity instanceof CrushingWheelControllerTileEntity))
|
||||
return;
|
||||
|
||||
CrushingWheelControllerTileEntity te = (CrushingWheelControllerTileEntity) tileEntity;
|
||||
if (!state.get(VALID) || CrushingWheelControllerTileEntity.isFrozen()) {
|
||||
if (te.crushingspeed != 0) {
|
||||
te.crushingspeed = 0;
|
||||
te.sendData();
|
||||
withTileEntityDo(world, pos, te -> {
|
||||
if (!state.get(VALID) || CrushingWheelControllerTileEntity.isFrozen()) {
|
||||
if (te.crushingspeed != 0) {
|
||||
te.crushingspeed = 0;
|
||||
te.sendData();
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (Direction d : Direction.values()) {
|
||||
if (d.getAxis().isVertical())
|
||||
continue;
|
||||
BlockState neighbour = world.getBlockState(pos.offset(d));
|
||||
if (!AllBlocks.CRUSHING_WHEEL.typeOf(neighbour))
|
||||
continue;
|
||||
if (neighbour.get(BlockStateProperties.AXIS) == d.getAxis())
|
||||
continue;
|
||||
KineticTileEntity wheelTe = (KineticTileEntity) world.getTileEntity(pos.offset(d));
|
||||
te.crushingspeed = Math.abs(wheelTe.getSpeed() / 50f);
|
||||
te.sendData();
|
||||
break;
|
||||
}
|
||||
for (Direction d : Direction.values()) {
|
||||
if (d.getAxis().isVertical())
|
||||
continue;
|
||||
BlockState neighbour = world.getBlockState(pos.offset(d));
|
||||
if (!AllBlocks.CRUSHING_WHEEL.typeOf(neighbour))
|
||||
continue;
|
||||
if (neighbour.get(BlockStateProperties.AXIS) == d.getAxis())
|
||||
continue;
|
||||
KineticTileEntity wheelTe = (KineticTileEntity) world.getTileEntity(pos.offset(d));
|
||||
te.crushingspeed = Math.abs(wheelTe.getSpeed() / 50f);
|
||||
te.sendData();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,29 +161,27 @@ public class CrushingWheelControllerBlock extends Block implements IHaveNoBlockI
|
|||
if (new AxisAlignedBB(pos).contains(entity.getPositionVec()))
|
||||
return VoxelShapes.empty();
|
||||
|
||||
CrushingWheelControllerTileEntity te = (CrushingWheelControllerTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return VoxelShapes.fullCube();
|
||||
if (te.processingEntity == entity)
|
||||
return VoxelShapes.empty();
|
||||
try {
|
||||
CrushingWheelControllerTileEntity te = getTileEntity(worldIn, pos);
|
||||
if (te.processingEntity == entity)
|
||||
return VoxelShapes.empty();
|
||||
} catch (TileEntityException e) {}
|
||||
}
|
||||
return VoxelShapes.fullCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
if (worldIn.getTileEntity(pos) == null)
|
||||
return;
|
||||
CrushingWheelControllerTileEntity te = (CrushingWheelControllerTileEntity) worldIn.getTileEntity(pos);
|
||||
for (int slot = 0; slot < te.inventory.getSlots(); slot++) {
|
||||
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(),
|
||||
te.inventory.getStackInSlot(slot));
|
||||
}
|
||||
if (!state.hasTileEntity() || state.getBlock() == newState.getBlock())
|
||||
return;
|
||||
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
withTileEntityDo(worldIn, pos, te -> ItemHelper.dropContents(worldIn, pos, te.inventory));
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<CrushingWheelControllerTileEntity> getTileEntityClass() {
|
||||
return CrushingWheelControllerTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.simibubi.create.modules.contraptions.components.deployer;
|
|||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
|
||||
import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock;
|
||||
|
@ -26,7 +26,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public class DeployerBlock extends DirectionalAxisKineticBlock
|
||||
implements IWithTileEntity<DeployerTileEntity>, IPortableBlock {
|
||||
implements ITE<DeployerTileEntity>, IPortableBlock {
|
||||
|
||||
public static MovementBehaviour MOVEMENT = new DeployerMovementBehaviour();
|
||||
|
||||
|
@ -111,4 +111,9 @@ public class DeployerBlock extends DirectionalAxisKineticBlock
|
|||
return MOVEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DeployerTileEntity> getTileEntityClass() {
|
||||
return DeployerTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
import com.simibubi.create.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.particle.AirFlowParticleData;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.logistics.InWorldProcessing;
|
||||
import com.simibubi.create.modules.logistics.InWorldProcessing.Type;
|
||||
|
@ -267,15 +268,16 @@ public class AirCurrent {
|
|||
public void tickBelts() {
|
||||
for (Pair<BeltTileEntity, Type> pair : affectedBelts) {
|
||||
BeltTileEntity belt = pair.getKey();
|
||||
World world = belt.getWorld();
|
||||
InWorldProcessing.Type processingType = pair.getRight();
|
||||
|
||||
BeltTileEntity controller = belt.getControllerTE();
|
||||
if (controller == null)
|
||||
continue;
|
||||
World world = belt.getWorld();
|
||||
|
||||
controller.getInventory().forEachWithin(belt.index + .5f, .51f, (transported) -> {
|
||||
InWorldProcessing.spawnParticlesForProcessing(world,
|
||||
controller.getInventory().getVectorForOffset(transported.beltPosition), processingType);
|
||||
BeltHelper.getVectorForOffset(controller, transported.beltPosition), processingType);
|
||||
if (world.isRemote)
|
||||
return null;
|
||||
return InWorldProcessing.applyProcessing(transported, belt, processingType);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package com.simibubi.create.modules.contraptions.components.fan;
|
||||
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -17,7 +18,7 @@ import net.minecraft.world.IWorld;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EncasedFanBlock extends DirectionalKineticBlock implements IWithTileEntity<EncasedFanTileEntity> {
|
||||
public class EncasedFanBlock extends DirectionalKineticBlock implements ITE<EncasedFanTileEntity> {
|
||||
|
||||
public EncasedFanBlock() {
|
||||
super(Properties.from(Blocks.ANDESITE));
|
||||
|
@ -90,4 +91,9 @@ public class EncasedFanBlock extends DirectionalKineticBlock implements IWithTil
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<EncasedFanTileEntity> getTileEntityClass() {
|
||||
return EncasedFanTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.simibubi.create.AllTileEntities;
|
|||
import com.simibubi.create.config.AllConfigs;
|
||||
import com.simibubi.create.config.CKinetics;
|
||||
import com.simibubi.create.modules.contraptions.base.GeneratingKineticTileEntity;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simibubi.create.modules.contraptions.components.flywheel.engine;
|
|||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
|
||||
import net.minecraft.block.AbstractFurnaceBlock;
|
||||
|
@ -23,7 +23,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class FurnaceEngineBlock extends EngineBlock implements IWithTileEntity<FurnaceEngineTileEntity> {
|
||||
public class FurnaceEngineBlock extends EngineBlock implements ITE<FurnaceEngineTileEntity> {
|
||||
|
||||
public FurnaceEngineBlock() {
|
||||
super(Properties.from(Blocks.GOLD_BLOCK));
|
||||
|
@ -76,4 +76,9 @@ public class FurnaceEngineBlock extends EngineBlock implements IWithTileEntity<F
|
|||
event.setUseBlock(Result.DENY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<FurnaceEngineTileEntity> getTileEntityClass() {
|
||||
return FurnaceEngineTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.simibubi.create.modules.contraptions.components.millstone;
|
||||
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.item.ItemHelper;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -8,7 +11,6 @@ import net.minecraft.block.Blocks;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
|
@ -27,7 +29,7 @@ import net.minecraftforge.items.IItemHandler;
|
|||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class MillstoneBlock extends KineticBlock {
|
||||
public class MillstoneBlock extends KineticBlock implements ITE<MillstoneTileEntity> {
|
||||
|
||||
public MillstoneBlock() {
|
||||
super(Properties.from(Blocks.ANDESITE));
|
||||
|
@ -58,23 +60,19 @@ public class MillstoneBlock extends KineticBlock {
|
|||
BlockRayTraceResult hit) {
|
||||
if (!player.getHeldItem(handIn).isEmpty())
|
||||
return false;
|
||||
if (worldIn.getTileEntity(pos) == null)
|
||||
return false;
|
||||
if (worldIn.isRemote)
|
||||
return true;
|
||||
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof MillstoneTileEntity))
|
||||
return false;
|
||||
MillstoneTileEntity millstone = (MillstoneTileEntity) tileEntity;
|
||||
withTileEntityDo(worldIn, pos, millstone -> {
|
||||
IItemHandlerModifiable inv = millstone.outputInv;
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
||||
player.inventory.placeItemBackInInventory(worldIn, inv.getStackInSlot(slot));
|
||||
inv.setStackInSlot(slot, ItemStack.EMPTY);
|
||||
}
|
||||
millstone.markDirty();
|
||||
millstone.sendData();
|
||||
});
|
||||
|
||||
IItemHandlerModifiable inv = millstone.outputInv;
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
||||
player.inventory.placeItemBackInInventory(worldIn, inv.getStackInSlot(slot));
|
||||
inv.setStackInSlot(slot, ItemStack.EMPTY);
|
||||
}
|
||||
millstone.markDirty();
|
||||
millstone.sendData();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -87,15 +85,17 @@ public class MillstoneBlock extends KineticBlock {
|
|||
if (!(entityIn instanceof ItemEntity))
|
||||
return;
|
||||
|
||||
BlockPos pos = entityIn.getPosition();
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof MillstoneTileEntity)) {
|
||||
tileEntity = worldIn.getTileEntity(pos.down());
|
||||
if (!(tileEntity instanceof MillstoneTileEntity))
|
||||
return;
|
||||
MillstoneTileEntity millstone = null;
|
||||
for (BlockPos pos : Iterate.hereAndBelow(entityIn.getPosition())) {
|
||||
try {
|
||||
millstone = getTileEntity(worldIn, pos);
|
||||
} catch (TileEntityException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (millstone == null)
|
||||
return;
|
||||
|
||||
MillstoneTileEntity millstone = (MillstoneTileEntity) tileEntity;
|
||||
ItemEntity itemEntity = (ItemEntity) entityIn;
|
||||
LazyOptional<IItemHandler> capability = millstone.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
||||
if (!capability.isPresent())
|
||||
|
@ -111,18 +111,10 @@ public class MillstoneBlock extends KineticBlock {
|
|||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof MillstoneTileEntity))
|
||||
return;
|
||||
MillstoneTileEntity te = (MillstoneTileEntity) tileEntity;
|
||||
for (int slot = 0; slot < te.inputInv.getSlots(); slot++) {
|
||||
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(),
|
||||
te.inputInv.getStackInSlot(slot));
|
||||
}
|
||||
for (int slot = 0; slot < te.outputInv.getSlots(); slot++) {
|
||||
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(),
|
||||
te.outputInv.getStackInSlot(slot));
|
||||
}
|
||||
withTileEntityDo(worldIn, pos, te -> {
|
||||
ItemHelper.dropContents(worldIn, pos, te.inputInv);
|
||||
ItemHelper.dropContents(worldIn, pos, te.outputInv);
|
||||
});
|
||||
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
@ -138,4 +130,9 @@ public class MillstoneBlock extends KineticBlock {
|
|||
return Axis.Y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MillstoneTileEntity> getTileEntityClass() {
|
||||
return MillstoneTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simibubi.create.modules.contraptions.components.mixer;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IHaveCustomBlockItem;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticBlock;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
|
||||
public class MechanicalMixerBlock extends KineticBlock
|
||||
implements IWithTileEntity<MechanicalMixerTileEntity>, IHaveCustomBlockItem {
|
||||
implements ITE<MechanicalMixerTileEntity>, IHaveCustomBlockItem {
|
||||
|
||||
public MechanicalMixerBlock() {
|
||||
super(Properties.from(Blocks.ANDESITE));
|
||||
|
@ -90,4 +90,9 @@ public class MechanicalMixerBlock extends KineticBlock
|
|||
return new BasinOperatorBlockItem(AllBlocks.MECHANICAL_MIXER, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MechanicalMixerTileEntity> getTileEntityClass() {
|
||||
return MechanicalMixerTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ import java.util.Optional;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IHaveCustomBlockItem;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.item.ItemHelper;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock;
|
||||
|
@ -18,7 +17,7 @@ import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.I
|
|||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.TransportedItemStack;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -39,7 +38,7 @@ import net.minecraft.world.IWorldReader;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public class MechanicalPressBlock extends HorizontalKineticBlock
|
||||
implements IWithTileEntity<MechanicalPressTileEntity>, IBeltAttachment, IHaveCustomBlockItem {
|
||||
implements ITE<MechanicalPressTileEntity>, IBeltAttachment, IHaveCustomBlockItem {
|
||||
|
||||
public MechanicalPressBlock() {
|
||||
super(Properties.from(Blocks.PISTON));
|
||||
|
@ -63,17 +62,15 @@ public class MechanicalPressBlock extends HorizontalKineticBlock
|
|||
boolean isMoving) {
|
||||
if (worldIn.isRemote)
|
||||
return;
|
||||
MechanicalPressTileEntity te = (MechanicalPressTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return;
|
||||
|
||||
if (worldIn.isBlockPowered(pos)) {
|
||||
withTileEntityDo(worldIn, pos, te -> {
|
||||
if (!worldIn.isBlockPowered(pos)) {
|
||||
te.finished = false;
|
||||
return;
|
||||
}
|
||||
if (!te.finished && !te.running && te.getSpeed() != 0)
|
||||
te.start(Mode.WORLD);
|
||||
} else {
|
||||
te.finished = false;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,54 +131,61 @@ public class MechanicalPressBlock extends HorizontalKineticBlock
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean startProcessingItem(BeltTileEntity te, TransportedItemStack transported, BeltAttachmentState state) {
|
||||
MechanicalPressTileEntity pressTe = (MechanicalPressTileEntity) te.getWorld()
|
||||
.getTileEntity(state.attachmentPos);
|
||||
public boolean startProcessingItem(BeltTileEntity belt, TransportedItemStack transported,
|
||||
BeltAttachmentState state) {
|
||||
try {
|
||||
MechanicalPressTileEntity pressTe = getTileEntity(belt.getWorld(), state.attachmentPos);
|
||||
if (pressTe.getSpeed() == 0)
|
||||
return false;
|
||||
if (pressTe.running)
|
||||
return false;
|
||||
if (!pressTe.getRecipe(transported.stack).isPresent())
|
||||
return false;
|
||||
|
||||
if (pressTe == null || pressTe.getSpeed() == 0)
|
||||
return false;
|
||||
if (pressTe.running)
|
||||
return false;
|
||||
if (!pressTe.getRecipe(transported.stack).isPresent())
|
||||
return false;
|
||||
state.processingDuration = 1;
|
||||
pressTe.start(Mode.BELT);
|
||||
return true;
|
||||
|
||||
state.processingDuration = 1;
|
||||
pressTe.start(Mode.BELT);
|
||||
return true;
|
||||
} catch (TileEntityException e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processItem(BeltTileEntity te, TransportedItemStack transportedStack, BeltAttachmentState state) {
|
||||
MechanicalPressTileEntity pressTe = (MechanicalPressTileEntity) te.getWorld()
|
||||
.getTileEntity(state.attachmentPos);
|
||||
public boolean processItem(BeltTileEntity belt, TransportedItemStack transportedStack, BeltAttachmentState state) {
|
||||
try {
|
||||
MechanicalPressTileEntity pressTe = getTileEntity(belt.getWorld(), state.attachmentPos);
|
||||
|
||||
// Not powered
|
||||
if (pressTe == null || pressTe.getSpeed() == 0)
|
||||
return false;
|
||||
// Not powered
|
||||
if (pressTe.getSpeed() == 0)
|
||||
return false;
|
||||
|
||||
// Running
|
||||
if (pressTe.running) {
|
||||
if (pressTe.runningTicks == 30) {
|
||||
Optional<PressingRecipe> recipe = pressTe.getRecipe(transportedStack.stack);
|
||||
// Running
|
||||
if (!pressTe.running)
|
||||
return false;
|
||||
if (pressTe.runningTicks != 30)
|
||||
return true;
|
||||
|
||||
pressTe.pressedItems.clear();
|
||||
pressTe.pressedItems.add(transportedStack.stack);
|
||||
Optional<PressingRecipe> recipe = pressTe.getRecipe(transportedStack.stack);
|
||||
|
||||
if (!recipe.isPresent())
|
||||
return false;
|
||||
ItemStack out = recipe.get().getRecipeOutput().copy();
|
||||
List<ItemStack> multipliedOutput = ItemHelper.multipliedOutput(transportedStack.stack, out);
|
||||
if (multipliedOutput.isEmpty())
|
||||
transportedStack.stack = ItemStack.EMPTY;
|
||||
transportedStack.stack = multipliedOutput.get(0);
|
||||
pressTe.pressedItems.clear();
|
||||
pressTe.pressedItems.add(transportedStack.stack);
|
||||
|
||||
TileEntity controllerTE = te.getWorld().getTileEntity(te.getController());
|
||||
if (controllerTE != null && controllerTE instanceof BeltTileEntity)
|
||||
((SyncedTileEntity) controllerTE).sendData();
|
||||
pressTe.sendData();
|
||||
}
|
||||
if (!recipe.isPresent())
|
||||
return false;
|
||||
|
||||
ItemStack out = recipe.get().getRecipeOutput().copy();
|
||||
List<ItemStack> multipliedOutput = ItemHelper.multipliedOutput(transportedStack.stack, out);
|
||||
if (multipliedOutput.isEmpty())
|
||||
transportedStack.stack = ItemStack.EMPTY;
|
||||
transportedStack.stack = multipliedOutput.get(0);
|
||||
|
||||
BeltTileEntity controllerTE = belt.getControllerTE();
|
||||
if (controllerTE != null)
|
||||
controllerTE.sendData();
|
||||
pressTe.sendData();
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (TileEntityException e) {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -191,4 +195,9 @@ public class MechanicalPressBlock extends HorizontalKineticBlock
|
|||
return new BasinOperatorBlockItem(AllBlocks.MECHANICAL_PRESS, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<MechanicalPressTileEntity> getTileEntityClass() {
|
||||
return MechanicalPressTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ package com.simibubi.create.modules.contraptions.components.saw;
|
|||
|
||||
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
|
||||
import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.item.ItemHelper;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.components.actors.SawMovementBehaviour;
|
||||
|
@ -15,7 +16,6 @@ import net.minecraft.block.Blocks;
|
|||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
|
@ -33,7 +33,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SawBlock extends DirectionalAxisKineticBlock implements IWithTileEntity<SawTileEntity>, IPortableBlock {
|
||||
public class SawBlock extends DirectionalAxisKineticBlock implements ITE<SawTileEntity>, IPortableBlock {
|
||||
|
||||
public static final BooleanProperty RUNNING = BooleanProperty.create("running");
|
||||
public static DamageSource damageSourceSaw = new DamageSource("create.saw").setDamageBypassesArmor();
|
||||
|
@ -97,12 +97,13 @@ public class SawBlock extends DirectionalAxisKineticBlock implements IWithTileEn
|
|||
super.onLanded(worldIn, entityIn);
|
||||
if (!(entityIn instanceof ItemEntity))
|
||||
return;
|
||||
BlockPos pos = entityIn.getPosition();
|
||||
if (!(worldIn.getTileEntity(pos) instanceof SawTileEntity))
|
||||
return;
|
||||
if (entityIn.world.isRemote)
|
||||
return;
|
||||
|
||||
BlockPos pos = entityIn.getPosition();
|
||||
withTileEntityDo(entityIn.world, pos, te -> {
|
||||
if (te.getSpeed() == 0)
|
||||
return;
|
||||
te.insertItem((ItemEntity) entityIn);
|
||||
});
|
||||
}
|
||||
|
@ -129,19 +130,12 @@ public class SawBlock extends DirectionalAxisKineticBlock implements IWithTileEn
|
|||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (worldIn.getTileEntity(pos) == null)
|
||||
if (!state.hasTileEntity() || state.getBlock() == newState.getBlock())
|
||||
return;
|
||||
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
withTileEntityDo(worldIn, pos, te -> {
|
||||
for (int slot = 0; slot < te.inventory.getSlots(); slot++) {
|
||||
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(),
|
||||
te.inventory.getStackInSlot(slot));
|
||||
}
|
||||
});
|
||||
TileEntityBehaviour.destroy(worldIn, pos, FilteringBehaviour.TYPE);
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
withTileEntityDo(worldIn, pos, te -> ItemHelper.dropContents(worldIn, pos, te.inventory));
|
||||
TileEntityBehaviour.destroy(worldIn, pos, FilteringBehaviour.TYPE);
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -149,4 +143,9 @@ public class SawBlock extends DirectionalAxisKineticBlock implements IWithTileEn
|
|||
return MOVEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<SawTileEntity> getTileEntityClass() {
|
||||
return SawTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,8 +148,6 @@ public class SawTileEntity extends BlockBreakingKineticTileEntity {
|
|||
if (stack.isEmpty())
|
||||
continue;
|
||||
|
||||
// if (itemMovementFacing.getAxis() == Axis.Z)
|
||||
// itemMovementFacing = itemMovementFacing.getOpposite();
|
||||
if (((BeltTileEntity) te).tryInsertingFromSide(itemMovementFacing, stack, false))
|
||||
inventory.setStackInSlot(slot, ItemStack.EMPTY);
|
||||
else {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simibubi.create.modules.contraptions.components.turntable;
|
||||
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticBlock;
|
||||
|
@ -22,7 +23,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TurntableBlock extends KineticBlock {
|
||||
public class TurntableBlock extends KineticBlock implements ITE<TurntableTileEntity> {
|
||||
|
||||
public TurntableBlock() {
|
||||
super(Properties.from(Blocks.STRIPPED_SPRUCE_LOG));
|
||||
|
@ -40,51 +41,48 @@ public class TurntableBlock extends KineticBlock {
|
|||
|
||||
@Override
|
||||
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity e) {
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
if (!(te instanceof KineticTileEntity))
|
||||
return;
|
||||
if (!e.onGround)
|
||||
return;
|
||||
if (e.getMotion().y > 0)
|
||||
return;
|
||||
|
||||
float speed = ((KineticTileEntity) te).getSpeed() * 3/10;
|
||||
World world = e.getEntityWorld();
|
||||
|
||||
if (speed == 0)
|
||||
return;
|
||||
if (e.posY < pos.getY() + .5f)
|
||||
return;
|
||||
|
||||
if (world.isRemote && (e instanceof PlayerEntity)) {
|
||||
if (worldIn.getBlockState(e.getPosition()) != state) {
|
||||
Vec3d origin = VecHelper.getCenterOf(pos);
|
||||
Vec3d offset = e.getPositionVec().subtract(origin);
|
||||
offset = VecHelper.rotate(offset, MathHelper.clamp(speed, -16, 16) / 1f, Axis.Y);
|
||||
Vec3d movement = origin.add(offset).subtract(e.getPositionVec());
|
||||
e.setMotion(e.getMotion().add(movement));
|
||||
withTileEntityDo(worldIn, pos, te -> {
|
||||
float speed = ((KineticTileEntity) te).getSpeed() * 3 / 10;
|
||||
if (speed == 0)
|
||||
return;
|
||||
|
||||
World world = e.getEntityWorld();
|
||||
if (world.isRemote && (e instanceof PlayerEntity)) {
|
||||
if (worldIn.getBlockState(e.getPosition()) != state) {
|
||||
Vec3d origin = VecHelper.getCenterOf(pos);
|
||||
Vec3d offset = e.getPositionVec().subtract(origin);
|
||||
offset = VecHelper.rotate(offset, MathHelper.clamp(speed, -16, 16) / 1f, Axis.Y);
|
||||
Vec3d movement = origin.add(offset).subtract(e.getPositionVec());
|
||||
e.setMotion(e.getMotion().add(movement));
|
||||
e.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((e instanceof PlayerEntity))
|
||||
return;
|
||||
if (world.isRemote)
|
||||
return;
|
||||
|
||||
if ((e instanceof LivingEntity)) {
|
||||
float diff = e.getRotationYawHead() - speed;
|
||||
((LivingEntity) e).setIdleTime(20);
|
||||
e.setRenderYawOffset(diff);
|
||||
e.setRotationYawHead(diff);
|
||||
e.onGround = false;
|
||||
e.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((e instanceof PlayerEntity))
|
||||
return;
|
||||
if (world.isRemote)
|
||||
return;
|
||||
if ((e instanceof LivingEntity)) {
|
||||
float diff = e.getRotationYawHead() - speed;
|
||||
((LivingEntity) e).setIdleTime(20);
|
||||
e.setRenderYawOffset(diff);
|
||||
e.setRotationYawHead(diff);
|
||||
e.onGround = false;
|
||||
e.velocityChanged = true;
|
||||
}
|
||||
e.rotationYaw -= speed;
|
||||
|
||||
e.rotationYaw -= speed;
|
||||
});
|
||||
}
|
||||
|
||||
// IRotate:
|
||||
|
||||
@Override
|
||||
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||
return face == Direction.DOWN;
|
||||
|
@ -100,4 +98,9 @@ public class TurntableBlock extends KineticBlock {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<TurntableTileEntity> getTileEntityClass() {
|
||||
return TurntableTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.simibubi.create.modules.contraptions.components.turntable;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
@ -22,8 +22,12 @@ public class TurntableHandler {
|
|||
if (mc.isGamePaused())
|
||||
return;
|
||||
|
||||
KineticTileEntity te = (KineticTileEntity) mc.world.getTileEntity(pos);
|
||||
float speed = te.getSpeed() * 3/10;
|
||||
TileEntity tileEntity = mc.world.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof TurntableTileEntity))
|
||||
return;
|
||||
|
||||
TurntableTileEntity turnTable = (TurntableTileEntity) tileEntity;
|
||||
float speed = turnTable.getSpeed() * 3/10;
|
||||
|
||||
if (speed == 0)
|
||||
return;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.components.waterwheel;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -20,7 +21,7 @@ import net.minecraft.world.IWorld;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class WaterWheelBlock extends HorizontalKineticBlock {
|
||||
public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<WaterWheelTileEntity> {
|
||||
|
||||
public WaterWheelBlock() {
|
||||
super(Properties.from(Blocks.STRIPPED_SPRUCE_WOOD));
|
||||
|
@ -79,46 +80,42 @@ public class WaterWheelBlock extends HorizontalKineticBlock {
|
|||
}
|
||||
|
||||
private void updateFlowAt(BlockState state, World world, BlockPos pos, Direction f) {
|
||||
WaterWheelTileEntity te = (WaterWheelTileEntity) world.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return;
|
||||
if (f.getAxis() == state.get(HORIZONTAL_FACING).getAxis())
|
||||
return;
|
||||
IFluidState fluid = world.getFluidState(pos.offset(f));
|
||||
Vec3d flowVec = fluid.getFlow(world, pos.offset(f));
|
||||
Direction wf = state.get(HORIZONTAL_FACING);
|
||||
double flow = 0;
|
||||
|
||||
flowVec = flowVec.scale(f.getAxisDirection().getOffset());
|
||||
IFluidState fluid = world.getFluidState(pos.offset(f));
|
||||
Direction wf = state.get(HORIZONTAL_FACING);
|
||||
boolean clockwise = wf.getAxisDirection() == AxisDirection.POSITIVE;
|
||||
int clockwiseMultiplier = 2;
|
||||
flowVec = new Vec3d(Math.signum(flowVec.x), Math.signum(flowVec.y), Math.signum(flowVec.z));
|
||||
|
||||
if (wf.getAxis() == Axis.Z) {
|
||||
if (f.getAxis() == Axis.Y)
|
||||
flow = flowVec.x > 0 ^ !clockwise ? -flowVec.x * clockwiseMultiplier : -flowVec.x;
|
||||
if (f.getAxis() == Axis.X)
|
||||
flow = flowVec.y < 0 ^ !clockwise ? flowVec.y * clockwiseMultiplier : flowVec.y;
|
||||
}
|
||||
Vec3d vec = fluid.getFlow(world, pos.offset(f));
|
||||
vec = vec.scale(f.getAxisDirection().getOffset());
|
||||
vec = new Vec3d(Math.signum(vec.x), Math.signum(vec.y), Math.signum(vec.z));
|
||||
Vec3d flow = vec;
|
||||
|
||||
if (wf.getAxis() == Axis.X) {
|
||||
if (f.getAxis() == Axis.Y)
|
||||
flow = flowVec.z < 0 ^ !clockwise ? flowVec.z * clockwiseMultiplier : flowVec.z;
|
||||
if (f.getAxis() == Axis.Z)
|
||||
flow = flowVec.y > 0 ^ !clockwise ? -flowVec.y * clockwiseMultiplier : -flowVec.y;
|
||||
}
|
||||
withTileEntityDo(world, pos, te -> {
|
||||
double flowStrength = 0;
|
||||
|
||||
te.setFlow(f, (float) (flow * AllConfigs.SERVER.kinetics.waterWheelSpeed.get() / 2f));
|
||||
if (wf.getAxis() == Axis.Z) {
|
||||
if (f.getAxis() == Axis.Y)
|
||||
flowStrength = flow.x > 0 ^ !clockwise ? -flow.x * clockwiseMultiplier : -flow.x;
|
||||
if (f.getAxis() == Axis.X)
|
||||
flowStrength = flow.y < 0 ^ !clockwise ? flow.y * clockwiseMultiplier : flow.y;
|
||||
}
|
||||
|
||||
if (wf.getAxis() == Axis.X) {
|
||||
if (f.getAxis() == Axis.Y)
|
||||
flowStrength = flow.z < 0 ^ !clockwise ? flow.z * clockwiseMultiplier : flow.z;
|
||||
if (f.getAxis() == Axis.Z)
|
||||
flowStrength = flow.y > 0 ^ !clockwise ? -flow.y * clockwiseMultiplier : -flow.y;
|
||||
}
|
||||
|
||||
te.setFlow(f, (float) (flowStrength * AllConfigs.SERVER.kinetics.waterWheelSpeed.get() / 2f));
|
||||
});
|
||||
}
|
||||
|
||||
private void updateWheelSpeed(IWorld world, BlockPos pos) {
|
||||
if (world.isRemote())
|
||||
return;
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof WaterWheelTileEntity))
|
||||
return;
|
||||
WaterWheelTileEntity te = (WaterWheelTileEntity) tileEntity;
|
||||
te.updateGeneratedRotation();
|
||||
withTileEntityDo(world, pos, WaterWheelTileEntity::updateGeneratedRotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -159,4 +156,9 @@ public class WaterWheelBlock extends HorizontalKineticBlock {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<WaterWheelTileEntity> getTileEntityClass() {
|
||||
return WaterWheelTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.simibubi.create.modules.contraptions.processing;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.item.ItemHelper;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
|
||||
|
@ -12,7 +12,6 @@ import net.minecraft.block.material.PushReaction;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
|
@ -26,7 +25,7 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
|||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity> {
|
||||
public class BasinBlock extends Block implements ITE<BasinTileEntity> {
|
||||
|
||||
public BasinBlock() {
|
||||
super(Properties.from(Blocks.ANDESITE));
|
||||
|
@ -52,16 +51,16 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
|
|||
BlockRayTraceResult hit) {
|
||||
if (!player.getHeldItem(handIn).isEmpty())
|
||||
return false;
|
||||
if (worldIn.getTileEntity(pos) == null)
|
||||
return false;
|
||||
|
||||
BasinTileEntity te = (BasinTileEntity) worldIn.getTileEntity(pos);
|
||||
IItemHandlerModifiable inv = te.inventory.orElse(new ItemStackHandler(1));
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
||||
player.inventory.placeItemBackInInventory(worldIn, inv.getStackInSlot(slot));
|
||||
inv.setStackInSlot(slot, ItemStack.EMPTY);
|
||||
}
|
||||
te.onEmptied();
|
||||
try {
|
||||
BasinTileEntity te = getTileEntity(worldIn, pos);
|
||||
IItemHandlerModifiable inv = te.inventory.orElse(new ItemStackHandler(1));
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
||||
player.inventory.placeItemBackInInventory(worldIn, inv.getStackInSlot(slot));
|
||||
inv.setStackInSlot(slot, ItemStack.EMPTY);
|
||||
}
|
||||
te.onEmptied();
|
||||
} catch (TileEntityException e) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -75,18 +74,17 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
|
|||
return;
|
||||
if (!entityIn.isAlive())
|
||||
return;
|
||||
|
||||
BasinTileEntity te = (BasinTileEntity) worldIn.getTileEntity(entityIn.getPosition());
|
||||
ItemEntity itemEntity = (ItemEntity) entityIn;
|
||||
ItemStack insertItem = ItemHandlerHelper.insertItem(te.inputInventory, itemEntity.getItem().copy(), false);
|
||||
withTileEntityDo(worldIn, entityIn.getPosition(), te -> {
|
||||
ItemStack insertItem = ItemHandlerHelper.insertItem(te.inputInventory, itemEntity.getItem().copy(), false);
|
||||
|
||||
if (insertItem.isEmpty()) {
|
||||
itemEntity.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
itemEntity.setItem(insertItem);
|
||||
if (insertItem.isEmpty()) {
|
||||
itemEntity.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
itemEntity.setItem(insertItem);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,19 +94,15 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
|
|||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (worldIn.getTileEntity(pos) == null)
|
||||
if (!state.hasTileEntity() || state.getBlock() == newState.getBlock()) {
|
||||
return;
|
||||
|
||||
BasinTileEntity te = (BasinTileEntity) worldIn.getTileEntity(pos);
|
||||
IItemHandlerModifiable inv = te.inventory.orElse(new ItemStackHandler(1));
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
||||
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), inv.getStackInSlot(slot));
|
||||
}
|
||||
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
withTileEntityDo(worldIn, pos, te -> {
|
||||
ItemHelper.dropContents(worldIn, pos, te.inputInventory);
|
||||
ItemHelper.dropContents(worldIn, pos, te.outputInventory);
|
||||
});
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,12 +117,15 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
|
|||
|
||||
@Override
|
||||
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
if (te instanceof BasinTileEntity) {
|
||||
BasinTileEntity basinTileEntity = (BasinTileEntity) te;
|
||||
return ItemHelper.calcRedstoneFromInventory(basinTileEntity.inputInventory);
|
||||
}
|
||||
try {
|
||||
return ItemHelper.calcRedstoneFromInventory(getTileEntity(worldIn, pos).inputInventory);
|
||||
} catch (TileEntityException e) {}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BasinTileEntity> getTileEntityClass() {
|
||||
return BasinTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.processing;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
|
||||
|
@ -84,11 +85,11 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity {
|
|||
if (isRunning())
|
||||
return false;
|
||||
|
||||
TileEntity basinTE = world.getTileEntity(pos.down(2));
|
||||
if (basinTE == null || !(basinTE instanceof BasinTileEntity))
|
||||
Optional<BasinTileEntity> basinTe = getBasin();
|
||||
if (!basinTe.isPresent())
|
||||
return true;
|
||||
if (!basinInv.isPresent())
|
||||
basinInv = basinTE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
||||
basinInv = basinTe.get().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
||||
if (!basinInv.isPresent())
|
||||
return true;
|
||||
|
||||
|
@ -160,9 +161,7 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity {
|
|||
sendData();
|
||||
}
|
||||
|
||||
TileEntity basinTE = world.getTileEntity(pos.down(2));
|
||||
if (basinTE instanceof BasinTileEntity)
|
||||
((BasinTileEntity) basinTE).contentsChanged = false;
|
||||
getBasin().ifPresent(te -> te.contentsChanged = true);
|
||||
}
|
||||
|
||||
protected List<IRecipe<?>> getMatchingRecipes() {
|
||||
|
@ -176,6 +175,13 @@ public abstract class BasinOperatingTileEntity extends KineticTileEntity {
|
|||
|
||||
}
|
||||
|
||||
protected Optional<BasinTileEntity> getBasin() {
|
||||
TileEntity basinTE = world.getTileEntity(pos.down(2));
|
||||
if (!(basinTE instanceof BasinTileEntity))
|
||||
return Optional.empty();
|
||||
return Optional.of((BasinTileEntity) basinTE);
|
||||
}
|
||||
|
||||
protected abstract <C extends IInventory> boolean matchStaticFilters(IRecipe<C> recipe);
|
||||
|
||||
protected abstract <C extends IInventory> boolean matchBasinRecipe(IRecipe<C> recipe);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.simibubi.create.modules.contraptions.processing;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
||||
|
||||
|
@ -111,11 +113,7 @@ public class BasinTileEntity extends SyncedTileEntity implements ITickableTileEn
|
|||
}
|
||||
|
||||
public void onEmptied() {
|
||||
TileEntity te = world.getTileEntity(pos.up(2));
|
||||
if (te == null)
|
||||
return;
|
||||
if (te instanceof BasinOperatingTileEntity)
|
||||
((BasinOperatingTileEntity) te).basinRemoved = true;
|
||||
getOperator().ifPresent(te -> te.basinRemoved = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -137,13 +135,14 @@ public class BasinTileEntity extends SyncedTileEntity implements ITickableTileEn
|
|||
if (!contentsChanged)
|
||||
return;
|
||||
contentsChanged = false;
|
||||
getOperator().ifPresent(te -> te.basinChecker.scheduleUpdate());
|
||||
}
|
||||
|
||||
private Optional<BasinOperatingTileEntity> getOperator() {
|
||||
TileEntity te = world.getTileEntity(pos.up(2));
|
||||
if (te == null)
|
||||
return;
|
||||
if (te instanceof BasinOperatingTileEntity)
|
||||
((BasinOperatingTileEntity) te).basinChecker.scheduleUpdate();
|
||||
|
||||
return Optional.of((BasinOperatingTileEntity) te);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.simibubi.create.modules.contraptions.redstone;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -26,7 +26,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class AnalogLeverBlock extends HorizontalFaceBlock implements IWithTileEntity<AnalogLeverTileEntity> {
|
||||
public class AnalogLeverBlock extends HorizontalFaceBlock implements ITE<AnalogLeverTileEntity> {
|
||||
|
||||
public AnalogLeverBlock() {
|
||||
super(Properties.from(Blocks.LEVER));
|
||||
|
@ -50,23 +50,24 @@ public class AnalogLeverBlock extends HorizontalFaceBlock implements IWithTileEn
|
|||
return true;
|
||||
}
|
||||
|
||||
boolean sneak = player.isSneaking();
|
||||
AnalogLeverTileEntity te = getTileEntity(worldIn, pos);
|
||||
if (te == null)
|
||||
return true;
|
||||
try {
|
||||
boolean sneak = player.isSneaking();
|
||||
AnalogLeverTileEntity te = getTileEntity(worldIn, pos);
|
||||
te.changeState(sneak);
|
||||
float f = .25f + ((te.state + 5) / 15f) * .5f;
|
||||
worldIn.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.2F, f);
|
||||
} catch (TileEntityException e) {}
|
||||
|
||||
te.changeState(sneak);
|
||||
float f = .25f + ((te.state + 5) / 15f) * .5f;
|
||||
worldIn.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.2F, f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
|
||||
AnalogLeverTileEntity tileEntity = getTileEntity(blockAccess, pos);
|
||||
if (tileEntity == null)
|
||||
try {
|
||||
return getTileEntity(blockAccess, pos).state;
|
||||
} catch (TileEntityException e) {
|
||||
return 0;
|
||||
return tileEntity.state;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,21 +83,23 @@ public class AnalogLeverBlock extends HorizontalFaceBlock implements IWithTileEn
|
|||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
||||
AnalogLeverTileEntity tileEntity = getTileEntity(worldIn, pos);
|
||||
if (tileEntity == null)
|
||||
return;
|
||||
if (tileEntity.state != 0 && rand.nextFloat() < 0.25F)
|
||||
addParticles(stateIn, worldIn, pos, 0.5F);
|
||||
try {
|
||||
AnalogLeverTileEntity tileEntity = getTileEntity(worldIn, pos);
|
||||
if (tileEntity.state != 0 && rand.nextFloat() < 0.25F)
|
||||
addParticles(stateIn, worldIn, pos, 0.5F);
|
||||
} catch (TileEntityException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
AnalogLeverTileEntity tileEntity = getTileEntity(worldIn, pos);
|
||||
if (tileEntity != null && !isMoving && state.getBlock() != newState.getBlock()) {
|
||||
if (tileEntity.state != 0)
|
||||
updateNeighbors(state, worldIn, pos);
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
try {
|
||||
AnalogLeverTileEntity tileEntity = getTileEntity(worldIn, pos);
|
||||
if (!isMoving && state.getBlock() != newState.getBlock()) {
|
||||
if (tileEntity.state != 0)
|
||||
updateNeighbors(state, worldIn, pos);
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
} catch (TileEntityException e) {}
|
||||
}
|
||||
|
||||
private static void addParticles(BlockState state, IWorld worldIn, BlockPos pos, float alpha) {
|
||||
|
@ -127,4 +130,9 @@ public class AnalogLeverBlock extends HorizontalFaceBlock implements IWithTileEn
|
|||
super.fillStateContainer(builder.add(HORIZONTAL_FACING, FACE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<AnalogLeverTileEntity> getTileEntityClass() {
|
||||
return AnalogLeverTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.advanced.sequencer;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.RotatedPillarKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -31,8 +32,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
|
||||
public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock
|
||||
implements IWithTileEntity<SequencedGearshiftTileEntity> {
|
||||
public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implements ITE<SequencedGearshiftTileEntity> {
|
||||
|
||||
public static final BooleanProperty VERTICAL = BooleanProperty.create("vertical");
|
||||
public static final IntegerProperty STATE = IntegerProperty.create("state", 0, 5);
|
||||
|
@ -86,9 +86,7 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock
|
|||
return false;
|
||||
}
|
||||
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
|
||||
displayScreen((SequencedGearshiftTileEntity) worldIn.getTileEntity(pos));
|
||||
});
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> withTileEntityDo(worldIn, pos, this::displayScreen));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -135,4 +133,9 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<SequencedGearshiftTileEntity> getTileEntityClass() {
|
||||
return SequencedGearshiftTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.function.Consumer;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -13,7 +14,6 @@ import net.minecraft.nbt.CompoundNBT;
|
|||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -59,12 +59,13 @@ public enum AllBeltAttachments {
|
|||
|
||||
default void onAttachmentPlaced(IWorld world, BlockPos pos, BlockState state) {
|
||||
BlockPos beltPos = getBeltPositionForAttachment(world, pos, state);
|
||||
TileEntity te = world.getTileEntity(beltPos);
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
BeltTileEntity belt = BeltHelper.getSegmentTE(world, beltPos);
|
||||
|
||||
if (belt == null)
|
||||
return;
|
||||
BeltTileEntity belt = (BeltTileEntity) te;
|
||||
if (!isAttachedCorrectly(world, pos, belt.getPos(), state, belt.getBlockState()))
|
||||
if (!isAttachedCorrectly(world, pos, beltPos, state, world.getBlockState(beltPos)))
|
||||
return;
|
||||
|
||||
belt.attachmentTracker.addAttachment(world, pos);
|
||||
belt.markDirty();
|
||||
belt.sendData();
|
||||
|
@ -72,16 +73,18 @@ public enum AllBeltAttachments {
|
|||
|
||||
default void onAttachmentRemoved(IWorld world, BlockPos pos, BlockState state) {
|
||||
BlockPos beltPos = getBeltPositionForAttachment(world, pos, state);
|
||||
TileEntity te = world.getTileEntity(beltPos);
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
BeltTileEntity belt = BeltHelper.getSegmentTE(world, beltPos);
|
||||
|
||||
if (belt == null)
|
||||
return;
|
||||
BeltTileEntity belt = (BeltTileEntity) te;
|
||||
if (!isAttachedCorrectly(world, pos, belt.getPos(), state, belt.getBlockState()))
|
||||
if (!isAttachedCorrectly(world, pos, beltPos, state, world.getBlockState(beltPos)))
|
||||
return;
|
||||
|
||||
belt.attachmentTracker.removeAttachment(pos);
|
||||
belt.markDirty();
|
||||
belt.sendData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class BeltAttachmentState {
|
||||
|
@ -112,8 +115,8 @@ public enum AllBeltAttachments {
|
|||
World world = belt.getWorld();
|
||||
BlockPos beltPos = belt.getPos();
|
||||
BlockState beltState = belt.getBlockState();
|
||||
List<BlockPos> attachmentPositions = ba.attachment.getPotentialAttachmentPositions(world, beltPos,
|
||||
beltState);
|
||||
List<BlockPos> attachmentPositions =
|
||||
ba.attachment.getPotentialAttachmentPositions(world, beltPos, beltState);
|
||||
|
||||
for (BlockPos potentialPos : attachmentPositions) {
|
||||
if (!world.isBlockPresent(potentialPos))
|
||||
|
|
|
@ -10,11 +10,12 @@ import com.simibubi.create.AllBlocks;
|
|||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.block.IHaveColorHandler;
|
||||
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltMovementHandler.TransportedEntityInfo;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.BeltMovementHandler.TransportedEntityInfo;
|
||||
import com.simibubi.create.modules.logistics.block.belts.tunnel.BeltTunnelBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
|
@ -62,7 +63,7 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
|||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class BeltBlock extends HorizontalKineticBlock
|
||||
implements IHaveNoBlockItem, IWithTileEntity<BeltTileEntity>, IHaveColorHandler {
|
||||
implements IHaveNoBlockItem, ITE<BeltTileEntity>, IHaveColorHandler {
|
||||
|
||||
public static final IProperty<Slope> SLOPE = EnumProperty.create("slope", Slope.class);
|
||||
public static final IProperty<Part> PART = EnumProperty.create("part", Part.class);
|
||||
|
@ -77,8 +78,11 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face) {
|
||||
if (face.getAxis() != getRotationAxis(state))
|
||||
return false;
|
||||
BeltTileEntity beltEntity = (BeltTileEntity) world.getTileEntity(pos);
|
||||
return beltEntity != null && beltEntity.hasPulley();
|
||||
|
||||
try {
|
||||
return getTileEntity(world, pos).hasPulley();
|
||||
} catch (TileEntityException e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,15 +115,9 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
|
||||
@Override
|
||||
public void spawnAdditionalDrops(BlockState state, World worldIn, BlockPos pos, ItemStack stack) {
|
||||
withTileEntityDo(worldIn, pos, te -> {
|
||||
if (worldIn.isRemote)
|
||||
return;
|
||||
if (te.isController()) {
|
||||
BeltInventory inv = te.getInventory();
|
||||
for (TransportedItemStack s : inv.items)
|
||||
inv.eject(s);
|
||||
}
|
||||
});
|
||||
BeltTileEntity controllerTE = BeltHelper.getControllerTE(worldIn, pos);
|
||||
if (controllerTE != null)
|
||||
controllerTE.getInventory().ejectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,9 +145,6 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
|
||||
@Override
|
||||
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
|
||||
BeltTileEntity belt = null;
|
||||
belt = (BeltTileEntity) worldIn.getTileEntity(pos);
|
||||
|
||||
if (state.get(SLOPE) == Slope.VERTICAL)
|
||||
return;
|
||||
if (entityIn instanceof PlayerEntity) {
|
||||
|
@ -159,6 +154,8 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
if (player.abilities.isFlying)
|
||||
return;
|
||||
}
|
||||
|
||||
BeltTileEntity belt = BeltHelper.getSegmentTE(worldIn, pos);
|
||||
if (belt == null || belt.getSpeed() == 0)
|
||||
return;
|
||||
if (entityIn instanceof ItemEntity && entityIn.isAlive()) {
|
||||
|
@ -178,12 +175,12 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
return;
|
||||
}
|
||||
|
||||
BeltTileEntity controller = (BeltTileEntity) worldIn.getTileEntity(belt.getController());
|
||||
BeltTileEntity controller = BeltHelper.getControllerTE(worldIn, pos);
|
||||
if (controller == null || controller.passengers == null)
|
||||
return;
|
||||
if (controller.passengers.containsKey(entityIn)) {
|
||||
TransportedEntityInfo info = controller.passengers.get(entityIn);
|
||||
if (info.ticksSinceLastCollision != 0 || pos.equals(entityIn.getPosition()))
|
||||
if (info.getTicksSinceLastCollision() != 0 || pos.equals(entityIn.getPosition()))
|
||||
info.refresh(pos, state);
|
||||
} else {
|
||||
controller.passengers.put(entityIn, new TransportedEntityInfo(pos, state));
|
||||
|
@ -224,10 +221,9 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
return true;
|
||||
}
|
||||
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
BeltTileEntity belt = BeltHelper.getSegmentTE(worldIn, pos);
|
||||
if (belt == null)
|
||||
return false;
|
||||
BeltTileEntity belt = (BeltTileEntity) te;
|
||||
|
||||
if (isHand) {
|
||||
BeltTileEntity controllerBelt = belt.getControllerTE();
|
||||
|
@ -270,10 +266,6 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
World world = context.getWorld();
|
||||
TileEntity te = world.getTileEntity(context.getPos());
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
return ActionResultType.PASS;
|
||||
BeltTileEntity belt = (BeltTileEntity) te;
|
||||
PlayerEntity player = context.getPlayer();
|
||||
|
||||
if (state.get(CASING)) {
|
||||
|
@ -289,8 +281,11 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
if (world.isRemote)
|
||||
return ActionResultType.SUCCESS;
|
||||
world.setBlockState(context.getPos(), state.with(PART, Part.MIDDLE), 2);
|
||||
belt.detachKinetics();
|
||||
belt.attachKinetics();
|
||||
BeltTileEntity belt = BeltHelper.getSegmentTE(world, context.getPos());
|
||||
if (belt != null) {
|
||||
belt.detachKinetics();
|
||||
belt.attachKinetics();
|
||||
}
|
||||
if (!player.isCreative())
|
||||
player.inventory.placeItemBackInInventory(world, new ItemStack(AllBlocks.SHAFT.get()));
|
||||
return ActionResultType.SUCCESS;
|
||||
|
@ -365,15 +360,21 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos,
|
||||
ISelectionContext context) {
|
||||
VoxelShape shape = getShape(state, worldIn, pos, context);
|
||||
BeltTileEntity belt = (BeltTileEntity) worldIn.getTileEntity(pos);
|
||||
if (belt == null || context.getEntity() == null)
|
||||
return shape;
|
||||
BeltTileEntity controller = (BeltTileEntity) worldIn.getTileEntity(belt.getController());
|
||||
if (controller == null)
|
||||
return shape;
|
||||
if (controller.passengers == null || !controller.passengers.containsKey(context.getEntity())) {
|
||||
return BeltShapes.getCollisionShape(state);
|
||||
}
|
||||
|
||||
try {
|
||||
if (context.getEntity() == null)
|
||||
return shape;
|
||||
|
||||
BeltTileEntity belt = getTileEntity(worldIn, pos);
|
||||
BeltTileEntity controller = belt.getControllerTE();
|
||||
|
||||
if (controller == null)
|
||||
return shape;
|
||||
if (controller.passengers == null || !controller.passengers.containsKey(context.getEntity())) {
|
||||
return BeltShapes.getCollisionShape(state);
|
||||
}
|
||||
|
||||
} catch (TileEntityException e) {}
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
@ -445,12 +446,8 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
world.setBlockState(beltPos, currentState.with(CASING, false), 2);
|
||||
}
|
||||
|
||||
if (te.isController() && isVertical) {
|
||||
BeltInventory inventory = te.getInventory();
|
||||
for (TransportedItemStack s : inventory.items)
|
||||
inventory.eject(s);
|
||||
inventory.items.clear();
|
||||
}
|
||||
if (te.isController() && isVertical)
|
||||
te.getInventory().ejectAll();
|
||||
} else {
|
||||
world.destroyBlock(pos, true);
|
||||
return;
|
||||
|
@ -490,11 +487,8 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
TileEntity tileEntity = world.getTileEntity(currentPos);
|
||||
if (tileEntity instanceof BeltTileEntity) {
|
||||
BeltTileEntity te = (BeltTileEntity) tileEntity;
|
||||
if (te.isController()) {
|
||||
BeltInventory inv = te.getInventory();
|
||||
for (TransportedItemStack stack : inv.items)
|
||||
inv.eject(stack);
|
||||
}
|
||||
if (te.isController())
|
||||
te.getInventory().ejectAll();
|
||||
|
||||
te.remove();
|
||||
hasPulley = te.hasPulley();
|
||||
|
@ -608,4 +602,9 @@ public class BeltBlock extends HorizontalKineticBlock
|
|||
return new BeltColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BeltTileEntity> getTileEntityClass() {
|
||||
return BeltTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
public class BeltHelper {
|
||||
|
||||
public static BeltTileEntity getSegmentTE(IWorld world, BlockPos pos) {
|
||||
if (!world.isAreaLoaded(pos, 0))
|
||||
return null;
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof BeltTileEntity))
|
||||
return null;
|
||||
return (BeltTileEntity) tileEntity;
|
||||
}
|
||||
|
||||
public static BeltTileEntity getControllerTE(IWorld world, BlockPos pos) {
|
||||
BeltTileEntity segment = getSegmentTE(world, pos);
|
||||
if (segment == null)
|
||||
return null;
|
||||
BlockPos controllerPos = segment.controller;
|
||||
if (controllerPos == null)
|
||||
return null;
|
||||
return getSegmentTE(world, controllerPos);
|
||||
}
|
||||
|
||||
public static BeltTileEntity getBeltAtSegment(BeltTileEntity controller, int segment) {
|
||||
BlockPos pos = getPositionForOffset(controller, segment);
|
||||
TileEntity te = controller.getWorld().getTileEntity(pos);
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
return null;
|
||||
return (BeltTileEntity) te;
|
||||
}
|
||||
|
||||
public static BlockPos getPositionForOffset(BeltTileEntity controller, int offset) {
|
||||
BlockPos pos = controller.getPos();
|
||||
Vec3i vec = controller.getBeltFacing().getDirectionVec();
|
||||
Slope slope = controller.getBlockState().get(BeltBlock.SLOPE);
|
||||
int verticality = slope == Slope.DOWNWARD ? -1 : slope == Slope.UPWARD ? 1 : 0;
|
||||
|
||||
return pos.add(offset * vec.getX(), MathHelper.clamp(offset, 0, controller.beltLength - 1) * verticality,
|
||||
offset * vec.getZ());
|
||||
}
|
||||
|
||||
public static Vec3d getVectorForOffset(BeltTileEntity controller, float offset) {
|
||||
Slope slope = controller.getBlockState().get(BeltBlock.SLOPE);
|
||||
int verticality = slope == Slope.DOWNWARD ? -1 : slope == Slope.UPWARD ? 1 : 0;
|
||||
float verticalMovement = verticality;
|
||||
if (offset < .5)
|
||||
verticalMovement = 0;
|
||||
verticalMovement = verticalMovement * (Math.min(offset, controller.beltLength - .5f) - .5f);
|
||||
|
||||
Vec3d vec = VecHelper.getCenterOf(controller.getPos());
|
||||
Vec3d horizontalMovement = new Vec3d(controller.getBeltFacing().getDirectionVec()).scale(offset - .5f);
|
||||
|
||||
if (slope == Slope.VERTICAL)
|
||||
horizontalMovement = Vec3d.ZERO;
|
||||
|
||||
vec = vec.add(horizontalMovement).add(0, verticalMovement, 0);
|
||||
return vec;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,10 @@ import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
|||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.Tracker;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltMovementHandler.TransportedEntityInfo;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.BeltInventory;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.BeltMovementHandler;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.BeltMovementHandler.TransportedEntityInfo;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -99,7 +102,7 @@ public class BeltTileEntity extends KineticTileEntity {
|
|||
passengers.forEach((entity, info) -> {
|
||||
boolean canBeTransported = BeltMovementHandler.canBeTransported(entity);
|
||||
boolean leftTheBelt =
|
||||
info.ticksSinceLastCollision > ((getBlockState().get(BeltBlock.SLOPE) != HORIZONTAL) ? 3 : 1);
|
||||
info.getTicksSinceLastCollision() > ((getBlockState().get(BeltBlock.SLOPE) != HORIZONTAL) ? 3 : 1);
|
||||
if (!canBeTransported || leftTheBelt) {
|
||||
toRemove.add(entity);
|
||||
return;
|
||||
|
@ -193,7 +196,7 @@ public class BeltTileEntity extends KineticTileEntity {
|
|||
public void applyColor(DyeColor colorIn) {
|
||||
int colorValue = colorIn.getMapColor().colorValue;
|
||||
for (BlockPos blockPos : BeltBlock.getBeltChain(world, getController())) {
|
||||
BeltTileEntity belt = (BeltTileEntity) world.getTileEntity(blockPos);
|
||||
BeltTileEntity belt = BeltHelper.getSegmentTE(world, blockPos);
|
||||
if (belt == null)
|
||||
continue;
|
||||
belt.color = belt.color == -1 ? colorValue : ColorHelper.mixColors(belt.color, colorValue, .5f);
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.simibubi.create.foundation.utility.TessellatorHelper;
|
|||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -107,7 +108,7 @@ public class BeltTileEntityRenderer extends SafeTileEntityRenderer<BeltTileEntit
|
|||
int verticality = slope == Slope.DOWNWARD ? -1 : slope == Slope.UPWARD ? 1 : 0;
|
||||
boolean slopeAlongX = te.getBeltFacing().getAxis() == Axis.X;
|
||||
|
||||
for (TransportedItemStack transported : te.getInventory().items) {
|
||||
for (TransportedItemStack transported : te.getInventory().getItems()) {
|
||||
GlStateManager.pushMatrix();
|
||||
TessellatorHelper.fightZFighting(transported.angle);
|
||||
float offset = MathHelper.lerp(partialTicks, transported.prevBeltPosition, transported.beltPosition);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.contraptions.relays.belt.item;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -23,7 +23,7 @@ import net.minecraft.util.math.RayTraceResult;
|
|||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BeltConnectorItemHandler {
|
||||
public class BeltConnectorHandler {
|
||||
|
||||
private static Random r = new Random();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.contraptions.relays.belt.item;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -7,6 +7,7 @@ import com.simibubi.create.AllBlocks;
|
|||
import com.simibubi.create.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.item.IAddedByOther;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
import com.simibubi.create.modules.contraptions.relays.elementary.ShaftBlock;
|
||||
|
@ -17,6 +18,7 @@ import net.minecraft.item.ItemUseContext;
|
|||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
|
@ -184,8 +186,16 @@ public class BeltConnectorItem extends BlockItem implements IAddedByOther {
|
|||
if (axis != world.getBlockState(second).get(BlockStateProperties.AXIS))
|
||||
return false;
|
||||
|
||||
float speed1 = ((KineticTileEntity) world.getTileEntity(first)).getTheoreticalSpeed();
|
||||
float speed2 = ((KineticTileEntity) world.getTileEntity(second)).getTheoreticalSpeed();
|
||||
TileEntity tileEntity = world.getTileEntity(first);
|
||||
TileEntity tileEntity2 = world.getTileEntity(second);
|
||||
|
||||
if (!(tileEntity instanceof KineticTileEntity))
|
||||
return false;
|
||||
if (!(tileEntity2 instanceof KineticTileEntity))
|
||||
return false;
|
||||
|
||||
float speed1 = ((KineticTileEntity) tileEntity).getTheoreticalSpeed();
|
||||
float speed2 = ((KineticTileEntity) tileEntity2).getTheoreticalSpeed();
|
||||
if (Math.signum(speed1) != Math.signum(speed2) && speed1 != 0 && speed2 != 0)
|
||||
return false;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.contraptions.relays.belt.transport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -9,9 +9,13 @@ import java.util.function.Function;
|
|||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.tunnel.BeltTunnelBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.tunnel.BeltTunnelTileEntity;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -23,9 +27,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
@ -36,7 +38,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
|||
public class BeltInventory {
|
||||
|
||||
final BeltTileEntity belt;
|
||||
final List<TransportedItemStack> items;
|
||||
private final List<TransportedItemStack> items;
|
||||
final List<TransportedItemStack> toInsert;
|
||||
boolean beltMovementPositive;
|
||||
final float SEGMENT_WINDOW = .75f;
|
||||
|
@ -52,7 +54,7 @@ public class BeltInventory {
|
|||
// Reverse item collection if belt just reversed
|
||||
if (beltMovementPositive != movingPositive()) {
|
||||
beltMovementPositive = movingPositive();
|
||||
Collections.reverse(items);
|
||||
Collections.reverse(getItems());
|
||||
belt.markDirty();
|
||||
belt.sendData();
|
||||
}
|
||||
|
@ -68,7 +70,7 @@ public class BeltInventory {
|
|||
// Assuming the first entry is furthest on the belt
|
||||
TransportedItemStack stackInFront = null;
|
||||
TransportedItemStack current = null;
|
||||
Iterator<TransportedItemStack> iterator = items.iterator();
|
||||
Iterator<TransportedItemStack> iterator = getItems().iterator();
|
||||
|
||||
float beltSpeed = belt.getDirectionAwareBeltMovementSpeed();
|
||||
Direction movementFacing = belt.getMovementFacing();
|
||||
|
@ -121,7 +123,7 @@ public class BeltInventory {
|
|||
if (!onClient) {
|
||||
// Don't move if belt attachments want to continue processing
|
||||
if (segmentBefore != -1 && current.locked) {
|
||||
BeltTileEntity beltSegment = getBeltSegment(segmentBefore);
|
||||
BeltTileEntity beltSegment = BeltHelper.getBeltAtSegment(belt, segmentBefore);
|
||||
if (beltSegment != null) {
|
||||
|
||||
current.locked = false;
|
||||
|
@ -143,7 +145,7 @@ public class BeltInventory {
|
|||
int upcomingSegment = (int) (current.beltPosition + (beltMovementPositive ? .5f : -.5f));
|
||||
for (int segment = upcomingSegment; beltMovementPositive ? segment + .5f <= nextOffset
|
||||
: segment + .5f >= nextOffset; segment += beltMovementPositive ? 1 : -1) {
|
||||
BeltTileEntity beltSegment = getBeltSegment(segmentBefore);
|
||||
BeltTileEntity beltSegment = BeltHelper.getBeltAtSegment(belt, segmentBefore);
|
||||
if (beltSegment == null)
|
||||
break;
|
||||
for (BeltAttachmentState attachmentState : beltSegment.attachmentTracker.attachments) {
|
||||
|
@ -196,7 +198,7 @@ public class BeltInventory {
|
|||
if (segment == -1)
|
||||
continue;
|
||||
if (!world.isRemote)
|
||||
world.updateComparatorOutputLevel(getPositionForOffset(segment),
|
||||
world.updateComparatorOutputLevel(BeltHelper.getPositionForOffset(belt, segment),
|
||||
belt.getBlockState().getBlock());
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +209,8 @@ public class BeltInventory {
|
|||
continue;
|
||||
|
||||
int lastOffset = beltMovementPositive ? belt.beltLength - 1 : 0;
|
||||
BlockPos nextPosition = getPositionForOffset(beltMovementPositive ? belt.beltLength : -1);
|
||||
BlockPos nextPosition =
|
||||
BeltHelper.getPositionForOffset(belt, beltMovementPositive ? belt.beltLength : -1);
|
||||
BlockState state = world.getBlockState(nextPosition);
|
||||
|
||||
// next block is a basin or a saw
|
||||
|
@ -275,7 +278,7 @@ public class BeltInventory {
|
|||
}
|
||||
|
||||
private boolean stuckAtTunnel(int offset, ItemStack stack, Direction movementDirection) {
|
||||
BlockPos pos = getPositionForOffset(offset).up();
|
||||
BlockPos pos = BeltHelper.getPositionForOffset(belt, offset).up();
|
||||
if (!AllBlocks.BELT_TUNNEL.typeOf(belt.getWorld().getBlockState(pos)))
|
||||
return false;
|
||||
TileEntity te = belt.getWorld().getTileEntity(pos);
|
||||
|
@ -313,7 +316,7 @@ public class BeltInventory {
|
|||
private void flapTunnel(int offset, Direction side, boolean inward) {
|
||||
if (belt.getBlockState().get(BeltBlock.SLOPE) != Slope.HORIZONTAL)
|
||||
return;
|
||||
BlockPos pos = getPositionForOffset(offset).up();
|
||||
BlockPos pos = BeltHelper.getPositionForOffset(belt, offset).up();
|
||||
if (!AllBlocks.BELT_TUNNEL.typeOf(belt.getWorld().getBlockState(pos)))
|
||||
return;
|
||||
TileEntity te = belt.getWorld().getTileEntity(pos);
|
||||
|
@ -335,7 +338,7 @@ public class BeltInventory {
|
|||
else if (!beltMovementPositive)
|
||||
segmentPos += 1f;
|
||||
|
||||
for (TransportedItemStack stack : items)
|
||||
for (TransportedItemStack stack : getItems())
|
||||
if (isBlocking(segment, side, segmentPos, stack))
|
||||
return false;
|
||||
for (TransportedItemStack stack : toInsert)
|
||||
|
@ -358,23 +361,23 @@ public class BeltInventory {
|
|||
}
|
||||
|
||||
private void insert(TransportedItemStack newStack) {
|
||||
if (items.isEmpty())
|
||||
items.add(newStack);
|
||||
if (getItems().isEmpty())
|
||||
getItems().add(newStack);
|
||||
else {
|
||||
int index = 0;
|
||||
for (TransportedItemStack stack : items) {
|
||||
for (TransportedItemStack stack : getItems()) {
|
||||
if (stack.compareTo(newStack) > 0 == beltMovementPositive)
|
||||
break;
|
||||
index++;
|
||||
}
|
||||
items.add(index, newStack);
|
||||
getItems().add(index, newStack);
|
||||
}
|
||||
}
|
||||
|
||||
public TransportedItemStack getStackAtOffset(int offset) {
|
||||
float min = offset + .5f - (SEGMENT_WINDOW / 2);
|
||||
float max = offset + .5f + (SEGMENT_WINDOW / 2);
|
||||
for (TransportedItemStack stack : items) {
|
||||
for (TransportedItemStack stack : getItems()) {
|
||||
if (stack.beltPosition > max)
|
||||
break;
|
||||
if (stack.beltPosition > min)
|
||||
|
@ -384,16 +387,16 @@ public class BeltInventory {
|
|||
}
|
||||
|
||||
public void read(CompoundNBT nbt) {
|
||||
items.clear();
|
||||
getItems().clear();
|
||||
nbt.getList("Items", NBT.TAG_COMPOUND)
|
||||
.forEach(inbt -> items.add(TransportedItemStack.read((CompoundNBT) inbt)));
|
||||
.forEach(inbt -> getItems().add(TransportedItemStack.read((CompoundNBT) inbt)));
|
||||
beltMovementPositive = nbt.getBoolean("PositiveOrder");
|
||||
}
|
||||
|
||||
public CompoundNBT write() {
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
ListNBT itemsNBT = new ListNBT();
|
||||
items.forEach(stack -> itemsNBT.add(stack.serializeNBT()));
|
||||
getItems().forEach(stack -> itemsNBT.add(stack.serializeNBT()));
|
||||
nbt.put("Items", itemsNBT);
|
||||
nbt.putBoolean("PositiveOrder", beltMovementPositive);
|
||||
return nbt;
|
||||
|
@ -401,7 +404,7 @@ public class BeltInventory {
|
|||
|
||||
public void eject(TransportedItemStack stack) {
|
||||
ItemStack ejected = stack.stack;
|
||||
Vec3d outPos = getVectorForOffset(stack.beltPosition);
|
||||
Vec3d outPos = BeltHelper.getVectorForOffset(belt, stack.beltPosition);
|
||||
float movementSpeed = Math.max(Math.abs(belt.getBeltMovementSpeed()), 1 / 8f);
|
||||
Vec3d outMotion = new Vec3d(belt.getBeltChainDirection()).scale(movementSpeed).add(0, 1 / 8f, 0);
|
||||
outPos.add(outMotion.normalize());
|
||||
|
@ -412,40 +415,9 @@ public class BeltInventory {
|
|||
belt.getWorld().addEntity(entity);
|
||||
}
|
||||
|
||||
public Vec3d getVectorForOffset(float offset) {
|
||||
Slope slope = belt.getBlockState().get(BeltBlock.SLOPE);
|
||||
int verticality = slope == Slope.DOWNWARD ? -1 : slope == Slope.UPWARD ? 1 : 0;
|
||||
float verticalMovement = verticality;
|
||||
if (offset < .5)
|
||||
verticalMovement = 0;
|
||||
verticalMovement = verticalMovement * (Math.min(offset, belt.beltLength - .5f) - .5f);
|
||||
|
||||
Vec3d vec = VecHelper.getCenterOf(belt.getPos());
|
||||
Vec3d horizontalMovement = new Vec3d(belt.getBeltFacing().getDirectionVec()).scale(offset - .5f);
|
||||
|
||||
if (slope == Slope.VERTICAL)
|
||||
horizontalMovement = Vec3d.ZERO;
|
||||
|
||||
vec = vec.add(horizontalMovement).add(0, verticalMovement, 0);
|
||||
return vec;
|
||||
}
|
||||
|
||||
private BeltTileEntity getBeltSegment(int segment) {
|
||||
BlockPos pos = getPositionForOffset(segment);
|
||||
TileEntity te = belt.getWorld().getTileEntity(pos);
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
return null;
|
||||
return (BeltTileEntity) te;
|
||||
}
|
||||
|
||||
private BlockPos getPositionForOffset(int offset) {
|
||||
BlockPos pos = belt.getPos();
|
||||
Vec3i vec = belt.getBeltFacing().getDirectionVec();
|
||||
Slope slope = belt.getBlockState().get(BeltBlock.SLOPE);
|
||||
int verticality = slope == Slope.DOWNWARD ? -1 : slope == Slope.UPWARD ? 1 : 0;
|
||||
|
||||
return pos.add(offset * vec.getX(), MathHelper.clamp(offset, 0, belt.beltLength - 1) * verticality,
|
||||
offset * vec.getZ());
|
||||
public void ejectAll() {
|
||||
getItems().forEach(this::eject);
|
||||
getItems().clear();
|
||||
}
|
||||
|
||||
private boolean movingPositive() {
|
||||
|
@ -460,7 +432,7 @@ public class BeltInventory {
|
|||
Function<TransportedItemStack, List<TransportedItemStack>> callback) {
|
||||
List<TransportedItemStack> toBeAdded = new ArrayList<>();
|
||||
boolean dirty = false;
|
||||
for (Iterator<TransportedItemStack> iterator = items.iterator(); iterator.hasNext();) {
|
||||
for (Iterator<TransportedItemStack> iterator = getItems().iterator(); iterator.hasNext();) {
|
||||
TransportedItemStack transportedItemStack = iterator.next();
|
||||
if (Math.abs(position - transportedItemStack.beltPosition) < distance) {
|
||||
List<TransportedItemStack> apply = callback.apply(transportedItemStack);
|
||||
|
@ -478,4 +450,8 @@ public class BeltInventory {
|
|||
}
|
||||
}
|
||||
|
||||
public List<TransportedItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.contraptions.relays.belt.transport;
|
||||
|
||||
import static net.minecraft.entity.MoverType.SELF;
|
||||
import static net.minecraft.util.Direction.AxisDirection.NEGATIVE;
|
||||
|
@ -9,8 +9,10 @@ import java.util.List;
|
|||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -50,6 +52,10 @@ public class BeltMovementHandler {
|
|||
ticksSinceLastCollision++;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getTicksSinceLastCollision() {
|
||||
return ticksSinceLastCollision;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canBeTransported(Entity entity) {
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.contraptions.relays.belt.transport;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.contraptions.relays.belt.transport;
|
||||
|
||||
import java.util.Random;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.encased;
|
||||
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class AdjustablePulleyBlock extends EncasedBeltBlock implements IWithTileEntity<AdjustablePulleyTileEntity> {
|
||||
public class AdjustablePulleyBlock extends EncasedBeltBlock implements ITE<AdjustablePulleyTileEntity> {
|
||||
|
||||
public static BooleanProperty POWERED = BlockStateProperties.POWERED;
|
||||
|
||||
|
@ -34,8 +34,9 @@ public class AdjustablePulleyBlock extends EncasedBeltBlock implements IWithTile
|
|||
|
||||
@Override
|
||||
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
|
||||
if (oldState.getBlock() != state.getBlock())
|
||||
withTileEntityDo(worldIn, pos, AdjustablePulleyTileEntity::neighborChanged);
|
||||
if (oldState.getBlock() == state.getBlock())
|
||||
return;
|
||||
withTileEntityDo(worldIn, pos, AdjustablePulleyTileEntity::neighborChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,4 +62,9 @@ public class AdjustablePulleyBlock extends EncasedBeltBlock implements IWithTile
|
|||
worldIn.setBlockState(pos, state.cycle(POWERED), 18);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<AdjustablePulleyTileEntity> getTileEntityClass() {
|
||||
return AdjustablePulleyTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.simibubi.create.foundation.utility.Lang;
|
|||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.base.RotatedPillarKineticBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.encased;
|
||||
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.modules.contraptions.RotationPropagator;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.gearbox.GearshiftTileEntity;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -17,7 +17,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GearshiftBlock extends EncasedShaftBlock {
|
||||
public class GearshiftBlock extends EncasedShaftBlock implements ITE<GearshiftTileEntity> {
|
||||
|
||||
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class GearshiftBlock extends EncasedShaftBlock {
|
|||
|
||||
boolean previouslyPowered = state.get(POWERED);
|
||||
if (previouslyPowered != worldIn.isBlockPowered(pos)) {
|
||||
RotationPropagator.handleRemoved(worldIn, pos, (KineticTileEntity) worldIn.getTileEntity(pos));
|
||||
withTileEntityDo(worldIn, pos, te -> RotationPropagator.handleRemoved(worldIn, pos, te));
|
||||
worldIn.setBlockState(pos, state.cycle(POWERED), 2);
|
||||
}
|
||||
}
|
||||
|
@ -60,4 +60,9 @@ public class GearshiftBlock extends EncasedShaftBlock {
|
|||
return super.hasShaftTowards(world, pos, state, face);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<GearshiftTileEntity> getTileEntityClass() {
|
||||
return GearshiftTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@ import java.util.List;
|
|||
|
||||
import com.simibubi.create.foundation.block.IHaveCustomBlockModel;
|
||||
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FourWayBlock;
|
||||
import net.minecraft.block.PaneBlock;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -46,7 +47,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class WindowInABlockBlock extends PaneBlock
|
||||
implements IWithTileEntity<WindowInABlockTileEntity>, IHaveNoBlockItem, IHaveCustomBlockModel {
|
||||
implements ITE<WindowInABlockTileEntity>, IHaveNoBlockItem, IHaveCustomBlockModel {
|
||||
|
||||
public WindowInABlockBlock() {
|
||||
super(Properties.create(Material.ROCK));
|
||||
|
@ -70,32 +71,32 @@ public class WindowInABlockBlock extends PaneBlock
|
|||
|
||||
Vec3d start = player.getEyePosition(1);
|
||||
Vec3d end = start.add(player.getLookVec().scale(player.getAttribute(PlayerEntity.REACH_DISTANCE).getValue()));
|
||||
BlockRayTraceResult target = world
|
||||
.rayTraceBlocks(new RayTraceContext(start, end, BlockMode.OUTLINE, FluidMode.NONE, player));
|
||||
BlockRayTraceResult target =
|
||||
world.rayTraceBlocks(new RayTraceContext(start, end, BlockMode.OUTLINE, FluidMode.NONE, player));
|
||||
if (target == null || target.getHitVec() == null)
|
||||
return super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
|
||||
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(world, pos);
|
||||
if (tileEntity == null)
|
||||
return super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
|
||||
BlockState windowBlock = tileEntity.getWindowBlock();
|
||||
for (AxisAlignedBB bb : windowBlock.getShape(world, pos).toBoundingBoxList()) {
|
||||
if (bb.grow(.1d).contains(target.getHitVec().subtract(new Vec3d(pos)))) {
|
||||
windowBlock.getBlock().onBlockHarvested(world, pos, windowBlock, player);
|
||||
Block.spawnDrops(windowBlock, world, pos, null, player, player.getHeldItemMainhand());
|
||||
BlockState partialBlock = tileEntity.getPartialBlock();
|
||||
world.setBlockState(pos, partialBlock);
|
||||
for (Direction d : Direction.values()) {
|
||||
BlockPos offset = pos.offset(d);
|
||||
BlockState otherState = world.getBlockState(offset);
|
||||
partialBlock = partialBlock.updatePostPlacement(d, otherState, world, pos, offset);
|
||||
world.notifyBlockUpdate(offset, otherState, otherState, 2);
|
||||
}
|
||||
if (partialBlock != world.getBlockState(pos))
|
||||
try {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(world, pos);
|
||||
BlockState windowBlock = tileEntity.getWindowBlock();
|
||||
for (AxisAlignedBB bb : windowBlock.getShape(world, pos).toBoundingBoxList()) {
|
||||
if (bb.grow(.1d).contains(target.getHitVec().subtract(new Vec3d(pos)))) {
|
||||
windowBlock.getBlock().onBlockHarvested(world, pos, windowBlock, player);
|
||||
Block.spawnDrops(windowBlock, world, pos, null, player, player.getHeldItemMainhand());
|
||||
BlockState partialBlock = tileEntity.getPartialBlock();
|
||||
world.setBlockState(pos, partialBlock);
|
||||
return false;
|
||||
for (Direction d : Direction.values()) {
|
||||
BlockPos offset = pos.offset(d);
|
||||
BlockState otherState = world.getBlockState(offset);
|
||||
partialBlock = partialBlock.updatePostPlacement(d, otherState, world, pos, offset);
|
||||
world.notifyBlockUpdate(offset, otherState, otherState, 2);
|
||||
}
|
||||
if (partialBlock != world.getBlockState(pos))
|
||||
world.setBlockState(pos, partialBlock);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (TileEntityException e) {}
|
||||
|
||||
return super.removedByPlayer(state, world, pos, player, willHarvest, fluid);
|
||||
}
|
||||
|
@ -112,49 +113,36 @@ public class WindowInABlockBlock extends PaneBlock
|
|||
|
||||
@Override
|
||||
public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, BlockPos pos) {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(reader, pos);
|
||||
if (tileEntity == null)
|
||||
return super.propagatesSkylightDown(state, reader, pos);
|
||||
return tileEntity.getPartialBlock().propagatesSkylightDown(reader, pos);
|
||||
return getSurroundingBlockState(reader, pos).propagatesSkylightDown(reader, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean collisionExtendsVertically(BlockState state, IBlockReader world, BlockPos pos,
|
||||
Entity collidingEntity) {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(world, pos);
|
||||
if (tileEntity == null)
|
||||
return false;
|
||||
return tileEntity.getPartialBlock().collisionExtendsVertically(world, pos, collidingEntity);
|
||||
return getSurroundingBlockState(world, pos).collisionExtendsVertically(world, pos, collidingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBlockHardness(BlockState blockState, IBlockReader worldIn, BlockPos pos) {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(worldIn, pos);
|
||||
if (tileEntity == null)
|
||||
return 0;
|
||||
return tileEntity.getPartialBlock().getBlockHardness(worldIn, pos);
|
||||
return getSurroundingBlockState(worldIn, pos).getBlockHardness(worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExplosionResistance(BlockState state, IWorldReader world, BlockPos pos, Entity exploder,
|
||||
Explosion explosion) {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(world, pos);
|
||||
if (tileEntity == null)
|
||||
return 0;
|
||||
return tileEntity.getPartialBlock().getExplosionResistance(world, pos, exploder, explosion);
|
||||
return getSurroundingBlockState(world, pos).getExplosionResistance(world, pos, exploder, explosion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos,
|
||||
PlayerEntity player) {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(world, pos);
|
||||
if (tileEntity == null)
|
||||
return ItemStack.EMPTY;
|
||||
for (AxisAlignedBB bb : tileEntity.getWindowBlock().getShape(world, pos).toBoundingBoxList()) {
|
||||
BlockState window = getWindowBlockState(world, pos);
|
||||
for (AxisAlignedBB bb : window.getShape(world, pos).toBoundingBoxList()) {
|
||||
if (bb.grow(.1d).contains(target.getHitVec().subtract(new Vec3d(pos))))
|
||||
return tileEntity.getWindowBlock().getPickBlock(target, world, pos, player);
|
||||
return window.getPickBlock(target, world, pos, player);
|
||||
}
|
||||
return tileEntity.getPartialBlock().getPickBlock(target, world, pos, player);
|
||||
BlockState surrounding = getSurroundingBlockState(world, pos);
|
||||
return surrounding.getPickBlock(target, world, pos, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -171,11 +159,8 @@ public class WindowInABlockBlock extends PaneBlock
|
|||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(worldIn, pos);
|
||||
if (tileEntity == null)
|
||||
return makeCuboidShape(7, 0, 7, 9, 16, 9);
|
||||
VoxelShape shape1 = tileEntity.getPartialBlock().getShape(worldIn, pos, context);
|
||||
VoxelShape shape2 = tileEntity.getWindowBlock().getShape(worldIn, pos, context);
|
||||
VoxelShape shape1 = getSurroundingBlockState(worldIn, pos).getShape(worldIn, pos, context);
|
||||
VoxelShape shape2 = getWindowBlockState(worldIn, pos).getShape(worldIn, pos, context);
|
||||
return VoxelShapes.or(shape1, shape2);
|
||||
}
|
||||
|
||||
|
@ -188,10 +173,7 @@ public class WindowInABlockBlock extends PaneBlock
|
|||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public MaterialColor getMaterialColor(BlockState state, IBlockReader worldIn, BlockPos pos) {
|
||||
WindowInABlockTileEntity tileEntity = getTileEntity(worldIn, pos);
|
||||
if (tileEntity == null)
|
||||
return MaterialColor.AIR;
|
||||
return tileEntity.getPartialBlock().getMaterialColor(worldIn, pos);
|
||||
return getSurroundingBlockState(worldIn, pos).getMaterialColor(worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -200,8 +182,8 @@ public class WindowInABlockBlock extends PaneBlock
|
|||
withTileEntityDo(worldIn, currentPos, te -> {
|
||||
te.setWindowBlock(
|
||||
te.getWindowBlock().updatePostPlacement(facing, facingState, worldIn, currentPos, facingPos));
|
||||
BlockState blockState = te.getPartialBlock().updatePostPlacement(facing, facingState, worldIn, currentPos,
|
||||
facingPos);
|
||||
BlockState blockState =
|
||||
te.getPartialBlock().updatePostPlacement(facing, facingState, worldIn, currentPos, facingPos);
|
||||
if (blockState.getBlock() instanceof FourWayBlock) {
|
||||
for (BooleanProperty side : Arrays.asList(FourWayBlock.EAST, FourWayBlock.NORTH, FourWayBlock.SOUTH,
|
||||
FourWayBlock.WEST))
|
||||
|
@ -214,6 +196,20 @@ public class WindowInABlockBlock extends PaneBlock
|
|||
return stateIn;
|
||||
}
|
||||
|
||||
private BlockState getSurroundingBlockState(IBlockReader reader, BlockPos pos) {
|
||||
try {
|
||||
return getTileEntity(reader, pos).getPartialBlock();
|
||||
} catch (TileEntityException e) {}
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
private BlockState getWindowBlockState(IBlockReader reader, BlockPos pos) {
|
||||
try {
|
||||
return getTileEntity(reader, pos).getWindowBlock();
|
||||
} catch (TileEntityException e) {}
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public boolean isSideInvisible(BlockState state, BlockState adjacentBlockState, Direction side) {
|
||||
return false;
|
||||
|
@ -225,4 +221,9 @@ public class WindowInABlockBlock extends PaneBlock
|
|||
return new WindowInABlockModel(original);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<WindowInABlockTileEntity> getTileEntityClass() {
|
||||
return WindowInABlockTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package com.simibubi.create.modules.curiosities.partialWindows;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.simibubi.create.AllBlockTags;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.config.AllConfigs;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FourWayBlock;
|
||||
import net.minecraft.block.WallBlock;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
|
||||
import net.minecraftforge.eventbus.api.Event.Result;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
|
||||
@EventBusSubscriber(bus = Bus.FORGE)
|
||||
public class WindowLoggingHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void rightClickPartialBlockWithPaneMakesItWindowLogged(RightClickBlock event) {
|
||||
if (event.getUseItem() == Result.DENY)
|
||||
return;
|
||||
if (event.getEntityLiving().isSneaking())
|
||||
return;
|
||||
if (!event.getPlayer().isAllowEdit())
|
||||
return;
|
||||
if (!AllConfigs.SERVER.curiosities.allowGlassPanesInPartialBlocks.get())
|
||||
return;
|
||||
|
||||
ItemStack stack = event.getItemStack();
|
||||
if (stack.isEmpty())
|
||||
return;
|
||||
if (!(stack.getItem() instanceof BlockItem))
|
||||
return;
|
||||
BlockItem item = (BlockItem) stack.getItem();
|
||||
if (!item.isIn(Tags.Items.GLASS_PANES)
|
||||
&& (item.getBlock() == null || !item.getBlock().isIn(Tags.Blocks.GLASS_PANES)))
|
||||
return;
|
||||
|
||||
BlockPos pos = event.getPos();
|
||||
World world = event.getWorld();
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (!AllBlockTags.WINDOWABLE.matches(blockState))
|
||||
return;
|
||||
if (AllBlocks.WINDOW_IN_A_BLOCK.typeOf(blockState))
|
||||
return;
|
||||
|
||||
BlockState defaultState = AllBlocks.WINDOW_IN_A_BLOCK.get().getDefaultState();
|
||||
world.setBlockState(pos, defaultState);
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te != null && te instanceof WindowInABlockTileEntity) {
|
||||
WindowInABlockTileEntity wte = (WindowInABlockTileEntity) te;
|
||||
wte.setWindowBlock(item.getBlock().getDefaultState());
|
||||
wte.updateWindowConnections();
|
||||
|
||||
if (blockState.getBlock() instanceof FourWayBlock) {
|
||||
for (BooleanProperty side : Arrays.asList(FourWayBlock.EAST, FourWayBlock.NORTH, FourWayBlock.SOUTH,
|
||||
FourWayBlock.WEST))
|
||||
blockState = blockState.with(side, false);
|
||||
}
|
||||
if (blockState.getBlock() instanceof WallBlock)
|
||||
blockState = blockState.with(WallBlock.UP, true);
|
||||
|
||||
wte.setPartialBlock(blockState);
|
||||
wte.requestModelDataUpdate();
|
||||
|
||||
if (!event.getPlayer().isCreative())
|
||||
stack.shrink(1);
|
||||
event.getPlayer().swingArm(event.getHand());
|
||||
}
|
||||
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ import com.simibubi.create.foundation.utility.ColorHelper;
|
|||
import com.simibubi.create.modules.contraptions.components.fan.SplashingRecipe;
|
||||
import com.simibubi.create.modules.contraptions.processing.ProcessingRecipe;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.TransportedItemStack;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
|
|
@ -1,19 +1,22 @@
|
|||
package com.simibubi.create.modules.logistics.block;
|
||||
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.modules.contraptions.IWrenchable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
|
@ -25,7 +28,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RedstoneLinkBlock extends ProperDirectionalBlock {
|
||||
public class RedstoneLinkBlock extends ProperDirectionalBlock implements ITE<RedstoneLinkTileEntity>, IWrenchable {
|
||||
|
||||
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
||||
public static final BooleanProperty RECEIVER = BooleanProperty.create("receiver");
|
||||
|
@ -72,11 +75,7 @@ public class RedstoneLinkBlock extends ProperDirectionalBlock {
|
|||
|
||||
if (previouslyPowered != shouldPower) {
|
||||
worldIn.setBlockState(pos, state.cycle(POWERED), 2);
|
||||
|
||||
RedstoneLinkTileEntity te = (RedstoneLinkTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return;
|
||||
te.transmit(!previouslyPowered);
|
||||
withTileEntityDo(worldIn, pos, te -> te.transmit(!previouslyPowered));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,27 +117,35 @@ public class RedstoneLinkBlock extends ProperDirectionalBlock {
|
|||
@Override
|
||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
||||
BlockRayTraceResult hit) {
|
||||
|
||||
if (player.isSneaking()) {
|
||||
RedstoneLinkTileEntity te = (RedstoneLinkTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return false;
|
||||
|
||||
if (!worldIn.isRemote) {
|
||||
Boolean wasReceiver = state.get(RECEIVER);
|
||||
boolean blockPowered = worldIn.isBlockPowered(pos);
|
||||
worldIn.setBlockState(pos, state.cycle(RECEIVER).with(POWERED, blockPowered), 3);
|
||||
if (wasReceiver) {
|
||||
te.transmit(worldIn.isBlockPowered(pos));
|
||||
} else
|
||||
te.transmit(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.isSneaking())
|
||||
return toggleMode(state, worldIn, pos);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean toggleMode(BlockState state, World worldIn, BlockPos pos) {
|
||||
if (worldIn.isRemote)
|
||||
return true;
|
||||
try {
|
||||
RedstoneLinkTileEntity te = getTileEntity(worldIn, pos);
|
||||
Boolean wasReceiver = state.get(RECEIVER);
|
||||
boolean blockPowered = worldIn.isBlockPowered(pos);
|
||||
worldIn.setBlockState(pos, state.cycle(RECEIVER).with(POWERED, blockPowered), 3);
|
||||
if (wasReceiver) {
|
||||
te.transmit(worldIn.isBlockPowered(pos));
|
||||
} else
|
||||
te.transmit(false);
|
||||
return true;
|
||||
} catch (TileEntityException e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||
if (toggleMode(state, context.getWorld(), context.getPos()))
|
||||
return ActionResultType.SUCCESS;
|
||||
return IWrenchable.super.onWrenched(state, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(BlockState state, IBlockReader world, BlockPos pos, Direction side) {
|
||||
return side != null;
|
||||
|
@ -169,8 +176,8 @@ public class RedstoneLinkBlock extends ProperDirectionalBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PushReaction getPushReaction(BlockState state) {
|
||||
return PushReaction.BLOCK;
|
||||
public Class<RedstoneLinkTileEntity> getTileEntityClass() {
|
||||
return RedstoneLinkTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simibubi.create.modules.logistics.block;
|
||||
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -24,7 +25,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
|||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
|
||||
public class StockswitchBlock extends HorizontalBlock {
|
||||
public class StockswitchBlock extends HorizontalBlock implements ITE<StockswitchTileEntity> {
|
||||
|
||||
public static final IntegerProperty INDICATOR = IntegerProperty.create("indicator", 0, 6);
|
||||
|
||||
|
@ -52,10 +53,7 @@ public class StockswitchBlock extends HorizontalBlock {
|
|||
}
|
||||
|
||||
private void updateObservedInventory(BlockState state, IWorldReader world, BlockPos pos) {
|
||||
StockswitchTileEntity te = (StockswitchTileEntity) world.getTileEntity(pos);
|
||||
if (te == null)
|
||||
return;
|
||||
te.updateCurrentLevel();
|
||||
withTileEntityDo(world, pos, StockswitchTileEntity::updateCurrentLevel);
|
||||
}
|
||||
|
||||
private boolean isObserving(BlockState state, BlockPos pos, BlockPos observing) {
|
||||
|
@ -74,8 +72,10 @@ public class StockswitchBlock extends HorizontalBlock {
|
|||
|
||||
@Override
|
||||
public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
|
||||
StockswitchTileEntity te = (StockswitchTileEntity) blockAccess.getTileEntity(pos);
|
||||
return te == null || !te.powered ? 0 : 15;
|
||||
try {
|
||||
return getTileEntity(blockAccess, pos).powered ? 15 : 0;
|
||||
} catch (TileEntityException e) {}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,9 +87,7 @@ public class StockswitchBlock extends HorizontalBlock {
|
|||
@Override
|
||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
||||
BlockRayTraceResult hit) {
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
|
||||
displayScreen((StockswitchTileEntity) worldIn.getTileEntity(pos));
|
||||
});
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> withTileEntityDo(worldIn, pos, this::displayScreen));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -143,4 +141,9 @@ public class StockswitchBlock extends HorizontalBlock {
|
|||
return PushReaction.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<StockswitchTileEntity> getTileEntityClass() {
|
||||
return StockswitchTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import com.simibubi.create.foundation.behaviour.inventory.SingleTargetAutoExtrac
|
|||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.IBeltAttachment;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.TransportedItemStack;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.belts.observer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -7,7 +7,7 @@ import java.util.Random;
|
|||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
|
||||
import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.IWrenchable;
|
||||
|
@ -17,7 +17,7 @@ import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
|
|||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.TransportedItemStack;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -47,7 +47,7 @@ import net.minecraft.world.IWorld;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public class BeltObserverBlock extends HorizontalBlock
|
||||
implements IWithTileEntity<BeltObserverTileEntity>, IBeltAttachment, IWrenchable {
|
||||
implements ITE<BeltObserverTileEntity>, IBeltAttachment, IWrenchable {
|
||||
|
||||
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
||||
public static final BooleanProperty BELT = BooleanProperty.create("belt");
|
||||
|
@ -302,4 +302,9 @@ public class BeltObserverBlock extends HorizontalBlock
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BeltObserverTileEntity> getTileEntityClass() {
|
||||
return BeltObserverTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.belts.observer;
|
||||
|
||||
import com.simibubi.create.foundation.behaviour.ValueBoxTransform;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.belts.observer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -6,11 +6,12 @@ import com.simibubi.create.AllTileEntities;
|
|||
import com.simibubi.create.foundation.behaviour.base.SmartTileEntity;
|
||||
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
|
||||
import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.BeltObserverBlock.Mode;
|
||||
import com.simibubi.create.modules.logistics.block.belts.observer.BeltObserverBlock.Mode;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class BeltObserverTileEntity extends SmartTileEntity {
|
||||
|
@ -43,16 +44,16 @@ public class BeltObserverTileEntity extends SmartTileEntity {
|
|||
if (getBlockState().get(BeltObserverBlock.MODE) != Mode.DETECT)
|
||||
return;
|
||||
|
||||
TileEntity tileEntity =
|
||||
world.getTileEntity(pos.offset(getBlockState().get(BeltObserverBlock.HORIZONTAL_FACING)));
|
||||
if (!(tileEntity instanceof BeltTileEntity))
|
||||
BlockPos targetPos = pos.offset(getBlockState().get(BeltObserverBlock.HORIZONTAL_FACING));
|
||||
|
||||
BeltTileEntity beltTE = BeltHelper.getSegmentTE(world, targetPos);
|
||||
if (beltTE == null)
|
||||
return;
|
||||
BeltTileEntity belt = (BeltTileEntity) tileEntity;
|
||||
BeltTileEntity controllerTE = belt.getControllerTE();
|
||||
BeltTileEntity controllerTE = beltTE.getControllerTE();
|
||||
if (controllerTE == null)
|
||||
return;
|
||||
|
||||
controllerTE.getInventory().forEachWithin(belt.index + .5f, .45f, stack -> {
|
||||
controllerTE.getInventory().forEachWithin(beltTE.index + .5f, .45f, stack -> {
|
||||
if (filtering.test(stack.stack) && turnOffTicks != 6) {
|
||||
world.setBlockState(pos, getBlockState().with(BeltObserverBlock.POWERED, true));
|
||||
world.notifyNeighborsOfStateChange(pos, getBlockState().getBlock());
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.belts.observer;
|
||||
|
||||
import com.mojang.blaze3d.platform.GLX;
|
||||
import com.simibubi.create.foundation.behaviour.filtering.FilteringRenderer;
|
|
@ -1,13 +1,14 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.logistics.block.belts.tunnel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
import com.simibubi.create.modules.contraptions.IWrenchable;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -34,7 +35,7 @@ import net.minecraft.world.IWorld;
|
|||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BeltTunnelBlock extends Block implements IWithTileEntity<BeltTunnelTileEntity>, IWrenchable {
|
||||
public class BeltTunnelBlock extends Block implements ITE<BeltTunnelTileEntity>, IWrenchable {
|
||||
|
||||
public static final IProperty<Shape> SHAPE = EnumProperty.create("shape", Shape.class);
|
||||
public static final IProperty<Axis> HORIZONTAL_AXIS = BlockStateProperties.HORIZONTAL_AXIS;
|
||||
|
@ -245,4 +246,9 @@ public class BeltTunnelBlock extends Block implements IWithTileEntity<BeltTunnel
|
|||
super.fillStateContainer(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<BeltTunnelTileEntity> getTileEntityClass() {
|
||||
return BeltTunnelTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.logistics.block.belts.tunnel;
|
||||
|
||||
import static net.minecraft.block.Block.makeCuboidShape;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.logistics.block.belts.tunnel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
@ -10,7 +10,7 @@ import com.simibubi.create.AllBlocks;
|
|||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
||||
import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTunnelBlock.Shape;
|
||||
import com.simibubi.create.modules.logistics.block.belts.tunnel.BeltTunnelBlock.Shape;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.contraptions.relays.belt;
|
||||
package com.simibubi.create.modules.logistics.block.belts.tunnel;
|
||||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.foundation.block.SafeTileEntityRendererFast;
|
|
@ -6,7 +6,7 @@ import com.simibubi.create.foundation.utility.AngleHelper;
|
|||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.MovementBehaviour;
|
||||
import com.simibubi.create.modules.logistics.block.belts.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.belts.BeltAttachableLogisticalBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.simibubi.create.foundation.item.ItemHelper;
|
|||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.MovementBehaviour;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.MovementContext;
|
||||
import com.simibubi.create.modules.logistics.block.belts.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.item.filter.FilterItem;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
|
|
@ -5,7 +5,7 @@ import static net.minecraft.block.HorizontalBlock.HORIZONTAL_FACING;
|
|||
import com.simibubi.create.foundation.behaviour.ValueBoxTransform;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.logistics.block.belts.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.simibubi.create.foundation.behaviour.inventory.SingleTargetAutoExtrac
|
|||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.logistics.block.belts.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.funnel;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -7,14 +7,16 @@ import java.util.List;
|
|||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
|
||||
import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour;
|
||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock;
|
||||
import com.simibubi.create.modules.contraptions.components.contraptions.MovementBehaviour;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.IBeltAttachment;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.TransportedItemStack;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.transport.TransportedItemStack;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -36,7 +38,8 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class FunnelBlock extends AttachedLogisticalBlock implements IBeltAttachment, IWithTileEntity<FunnelTileEntity>, IPortableBlock {
|
||||
public class FunnelBlock extends AttachedLogisticalBlock
|
||||
implements IBeltAttachment, ITE<FunnelTileEntity>, IPortableBlock {
|
||||
|
||||
public static final BooleanProperty BELT = BooleanProperty.create("belt");
|
||||
public static final MovementBehaviour MOVEMENT = new FunnelMovementBehaviour();
|
||||
|
@ -123,17 +126,18 @@ public class FunnelBlock extends AttachedLogisticalBlock implements IBeltAttachm
|
|||
@Override
|
||||
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
|
||||
onAttachmentPlaced(worldIn, pos, state);
|
||||
if (worldIn.isRemote)
|
||||
return;
|
||||
|
||||
if (isOnBelt(worldIn, pos)) {
|
||||
TileEntity te = worldIn.getTileEntity(pos.down());
|
||||
if (!(te instanceof BeltTileEntity))
|
||||
BeltTileEntity belt = BeltHelper.getSegmentTE(worldIn, pos.down());
|
||||
if (belt == null)
|
||||
return;
|
||||
BeltTileEntity belt = (BeltTileEntity) te;
|
||||
|
||||
BeltTileEntity controllerBelt = belt.getControllerTE();
|
||||
if (controllerBelt == null)
|
||||
return;
|
||||
if (worldIn.isRemote)
|
||||
return;
|
||||
|
||||
controllerBelt.getInventory().forEachWithin(belt.index + .5f, .55f, (transportedItemStack) -> {
|
||||
controllerBelt.getInventory().eject(transportedItemStack);
|
||||
return Collections.emptyList();
|
||||
|
@ -199,7 +203,7 @@ public class FunnelBlock extends AttachedLogisticalBlock implements IBeltAttachm
|
|||
|
||||
public boolean process(BeltTileEntity belt, TransportedItemStack transported, BeltAttachmentState state) {
|
||||
TileEntity te = belt.getWorld().getTileEntity(state.attachmentPos);
|
||||
if (te == null || !(te instanceof FunnelTileEntity))
|
||||
if (!(te instanceof FunnelTileEntity))
|
||||
return false;
|
||||
FunnelTileEntity funnel = (FunnelTileEntity) te;
|
||||
ItemStack stack = funnel.tryToInsert(transported.stack);
|
||||
|
@ -219,4 +223,9 @@ public class FunnelBlock extends AttachedLogisticalBlock implements IBeltAttachm
|
|||
return MOVEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<FunnelTileEntity> getTileEntityClass() {
|
||||
return FunnelTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.funnel;
|
||||
|
||||
import com.simibubi.create.foundation.behaviour.ValueBoxTransform;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.extractor.ExtractorBlock;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.funnel;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.simibubi.create.modules.logistics.block.belts;
|
||||
package com.simibubi.create.modules.logistics.block.funnel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -11,14 +11,15 @@ import com.simibubi.create.foundation.behaviour.filtering.FilteringBehaviour;
|
|||
import com.simibubi.create.foundation.behaviour.inventory.InsertingBehaviour;
|
||||
import com.simibubi.create.foundation.behaviour.inventory.InventoryManagementBehaviour.Attachments;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltHelper;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.particles.ItemParticleData;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -103,10 +104,7 @@ public class FunnelTileEntity extends SmartTileEntity {
|
|||
BlockPos targetPos = pos.offset(AttachedLogisticalBlock.getBlockFacing(getBlockState()));
|
||||
if (!AllBlocks.BELT.typeOf(world.getBlockState(targetPos)))
|
||||
return null;
|
||||
TileEntity te = world.getTileEntity(targetPos);
|
||||
if (te == null || !(te instanceof BeltTileEntity))
|
||||
return null;
|
||||
return (BeltTileEntity) te;
|
||||
return BeltHelper.getSegmentTE(world, targetPos);
|
||||
}
|
||||
|
||||
public void spawnParticles(ItemStack stack) {
|
|
@ -75,10 +75,15 @@ public class FlexcrateBlock extends ProperDirectionalBlock {
|
|||
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
|
||||
if (oldState.getBlock() != state.getBlock() && state.hasTileEntity() && state.get(DOUBLE)
|
||||
&& state.get(FACING).getAxisDirection() == AxisDirection.POSITIVE) {
|
||||
FlexcrateTileEntity te = (FlexcrateTileEntity) worldIn.getTileEntity(pos);
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof FlexcrateTileEntity))
|
||||
return;
|
||||
|
||||
FlexcrateTileEntity te = (FlexcrateTileEntity) tileEntity;
|
||||
FlexcrateTileEntity other = te.getOtherCrate();
|
||||
if (other == null)
|
||||
return;
|
||||
|
||||
for (int slot = 0; slot < other.inventory.getSlots(); slot++) {
|
||||
te.inventory.setStackInSlot(slot, other.inventory.getStackInSlot(slot));
|
||||
other.inventory.setStackInSlot(slot, ItemStack.EMPTY);
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.inventory.container.Container;
|
|||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
public class FlexcrateContainer extends Container {
|
||||
|
@ -21,10 +22,13 @@ public class FlexcrateContainer extends Container {
|
|||
public FlexcrateContainer(int id, PlayerInventory inv, PacketBuffer extraData) {
|
||||
super(AllContainers.FLEXCRATE.type, id);
|
||||
ClientWorld world = Minecraft.getInstance().world;
|
||||
this.te = (FlexcrateTileEntity) world.getTileEntity(extraData.readBlockPos());
|
||||
this.te.handleUpdateTag(extraData.readCompoundTag());
|
||||
TileEntity tileEntity = world.getTileEntity(extraData.readBlockPos());
|
||||
this.playerInventory = inv;
|
||||
init();
|
||||
if (tileEntity instanceof FlexcrateTileEntity) {
|
||||
this.te = (FlexcrateTileEntity) tileEntity;
|
||||
this.te.handleUpdateTag(extraData.readCompoundTag());
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
public FlexcrateContainer(int id, PlayerInventory inv, FlexcrateTileEntity te) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.simibubi.create.foundation.behaviour.inventory.InsertingBehaviour;
|
|||
import com.simibubi.create.foundation.behaviour.inventory.InventoryManagementBehaviour.Attachments;
|
||||
import com.simibubi.create.modules.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.modules.contraptions.relays.belt.BeltTileEntity;
|
||||
import com.simibubi.create.modules.logistics.block.belts.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
|
||||
import com.simibubi.create.modules.logistics.block.extractor.ExtractorTileEntity;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.simibubi.create.modules.schematics.item.SchematicItem;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
|
@ -105,8 +106,8 @@ public class ServerSchematicLoader {
|
|||
|
||||
try {
|
||||
// Validate Referenced Block
|
||||
BlockState blockState = dimPos.world.getBlockState(dimPos.pos);
|
||||
if (!AllBlocks.SCHEMATIC_TABLE.typeOf(blockState))
|
||||
SchematicTableTileEntity table = getTable(dimPos);
|
||||
if (table == null)
|
||||
return;
|
||||
|
||||
// Delete schematic with same name
|
||||
|
@ -131,8 +132,7 @@ public class ServerSchematicLoader {
|
|||
activeUploads.put(playerSchematicId, new SchematicUploadEntry(writer, size, dimPos));
|
||||
|
||||
// Notify Tile Entity
|
||||
SchematicTableTileEntity tileEntity = (SchematicTableTileEntity) dimPos.world.getTileEntity(dimPos.pos);
|
||||
tileEntity.startUpload(schematic);
|
||||
table.startUpload(schematic);
|
||||
|
||||
} catch (IOException e) {
|
||||
Create.logger.error("Exception Thrown when starting Upload: " + playerSchematicId);
|
||||
|
@ -167,14 +167,12 @@ public class ServerSchematicLoader {
|
|||
try {
|
||||
entry.stream.write(data);
|
||||
entry.idleTime = 0;
|
||||
BlockState blockState = entry.tablePos.world.getBlockState(entry.tablePos.pos);
|
||||
if (!AllBlocks.SCHEMATIC_TABLE.typeOf(blockState))
|
||||
return;
|
||||
|
||||
SchematicTableTileEntity tileEntity =
|
||||
(SchematicTableTileEntity) entry.tablePos.world.getTileEntity(entry.tablePos.pos);
|
||||
tileEntity.uploadingProgress = (float) ((double) entry.bytesUploaded / entry.totalBytes);
|
||||
tileEntity.sendUpdate = true;
|
||||
SchematicTableTileEntity table = getTable(entry.tablePos);
|
||||
if (table == null)
|
||||
return;
|
||||
table.uploadingProgress = (float) ((double) entry.bytesUploaded / entry.totalBytes);
|
||||
table.sendUpdate = true;
|
||||
|
||||
} catch (IOException e) {
|
||||
Create.logger.error("Exception Thrown when uploading Schematic: " + playerSchematicId);
|
||||
|
@ -203,12 +201,17 @@ public class ServerSchematicLoader {
|
|||
if (dimpos == null)
|
||||
return;
|
||||
|
||||
BlockState blockState = dimpos.world.getBlockState(dimpos.pos);
|
||||
if (!AllBlocks.SCHEMATIC_TABLE.typeOf(blockState))
|
||||
return;
|
||||
SchematicTableTileEntity table = getTable(dimpos);
|
||||
if (table != null)
|
||||
table.finishUpload();
|
||||
}
|
||||
|
||||
SchematicTableTileEntity tileEntity = (SchematicTableTileEntity) dimpos.world.getTileEntity(dimpos.pos);
|
||||
tileEntity.finishUpload();
|
||||
public SchematicTableTileEntity getTable(DimensionPos dimpos) {
|
||||
TileEntity te = dimpos.world.getTileEntity(dimpos.pos);
|
||||
if (!(te instanceof SchematicTableTileEntity))
|
||||
return null;
|
||||
SchematicTableTileEntity table = (SchematicTableTileEntity) te;
|
||||
return table;
|
||||
}
|
||||
|
||||
public void handleFinishedUpload(ServerPlayerEntity player, String schematic) {
|
||||
|
@ -227,11 +230,12 @@ public class ServerSchematicLoader {
|
|||
if (!AllBlocks.SCHEMATIC_TABLE.typeOf(blockState))
|
||||
return;
|
||||
|
||||
SchematicTableTileEntity tileEntity = (SchematicTableTileEntity) dimpos.world.getTileEntity(dimpos.pos);
|
||||
tileEntity.finishUpload();
|
||||
tileEntity.inventory.setStackInSlot(0, ItemStack.EMPTY);
|
||||
tileEntity.inventory.setStackInSlot(1,
|
||||
SchematicItem.create(schematic, player.getName().getFormattedText()));
|
||||
SchematicTableTileEntity table = getTable(dimpos);
|
||||
if (table == null)
|
||||
return;
|
||||
table.finishUpload();
|
||||
table.inventory.setStackInSlot(0, ItemStack.EMPTY);
|
||||
table.inventory.setStackInSlot(1, SchematicItem.create(schematic, player.getName().getFormattedText()));
|
||||
|
||||
} catch (IOException e) {
|
||||
Create.logger.error("Exception Thrown when finishing Upload: " + playerSchematicId);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.simibubi.create.modules.schematics.block;
|
||||
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.item.ItemHelper;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -9,7 +11,6 @@ import net.minecraft.block.HorizontalBlock;
|
|||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.state.StateContainer.Builder;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -22,7 +23,7 @@ import net.minecraft.world.IBlockReader;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
public class SchematicTableBlock extends HorizontalBlock {
|
||||
public class SchematicTableBlock extends HorizontalBlock implements ITE<SchematicTableTileEntity> {
|
||||
|
||||
public SchematicTableBlock() {
|
||||
super(Properties.from(Blocks.OAK_PLANKS));
|
||||
|
@ -50,7 +51,8 @@ public class SchematicTableBlock extends HorizontalBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos,
|
||||
ISelectionContext context) {
|
||||
return AllShapes.TABLE_POLE_SHAPE;
|
||||
}
|
||||
|
||||
|
@ -67,15 +69,12 @@ public class SchematicTableBlock extends HorizontalBlock {
|
|||
@Override
|
||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
||||
BlockRayTraceResult hit) {
|
||||
if (worldIn.isRemote)
|
||||
return true;
|
||||
|
||||
if (worldIn.isRemote) {
|
||||
return true;
|
||||
} else {
|
||||
SchematicTableTileEntity te = (SchematicTableTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te != null)
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
|
||||
return true;
|
||||
}
|
||||
withTileEntityDo(worldIn, pos,
|
||||
te -> NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,19 +84,16 @@ public class SchematicTableBlock extends HorizontalBlock {
|
|||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (worldIn.getTileEntity(pos) == null)
|
||||
if (!state.hasTileEntity() || state.getBlock() == newState.getBlock())
|
||||
return;
|
||||
|
||||
SchematicTableTileEntity te = (SchematicTableTileEntity) worldIn.getTileEntity(pos);
|
||||
for (int slot = 0; slot < te.inventory.getSlots(); slot++) {
|
||||
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(),
|
||||
te.inventory.getStackInSlot(slot));
|
||||
}
|
||||
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
withTileEntityDo(worldIn, pos, te -> ItemHelper.dropContents(worldIn, pos, te.inventory));
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<SchematicTableTileEntity> getTileEntityClass() {
|
||||
return SchematicTableTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraft.inventory.container.Container;
|
|||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
public class SchematicTableContainer extends Container {
|
||||
|
@ -24,9 +25,12 @@ public class SchematicTableContainer extends Container {
|
|||
super(AllContainers.SCHEMATIC_TABLE.type, id);
|
||||
player = inv.player;
|
||||
ClientWorld world = Minecraft.getInstance().world;
|
||||
this.te = (SchematicTableTileEntity) world.getTileEntity(extraData.readBlockPos());
|
||||
this.te.handleUpdateTag(extraData.readCompoundTag());
|
||||
init();
|
||||
TileEntity tileEntity = world.getTileEntity(extraData.readBlockPos());
|
||||
if (tileEntity instanceof SchematicTableTileEntity) {
|
||||
this.te = (SchematicTableTileEntity) tileEntity;
|
||||
this.te.handleUpdateTag(extraData.readCompoundTag());
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
public SchematicTableContainer(int id, PlayerInventory inv, SchematicTableTileEntity te) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simibubi.create.modules.schematics.block;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.item.ItemHelper;
|
||||
import com.simibubi.create.foundation.utility.AllShapes;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -9,8 +10,6 @@ import net.minecraft.block.Blocks;
|
|||
import net.minecraft.block.material.PushReaction;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -22,7 +21,7 @@ import net.minecraft.world.IWorldReader;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
public class SchematicannonBlock extends Block {
|
||||
public class SchematicannonBlock extends Block implements ITE<SchematicannonTileEntity> {
|
||||
|
||||
public SchematicannonBlock() {
|
||||
super(Properties.from(Blocks.DISPENSER));
|
||||
|
@ -55,44 +54,32 @@ public class SchematicannonBlock extends Block {
|
|||
|
||||
@Override
|
||||
public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) {
|
||||
((SchematicannonTileEntity) world.getTileEntity(pos)).findInventories();
|
||||
super.onNeighborChange(state, world, pos, neighbor);
|
||||
withTileEntityDo(world, pos, SchematicannonTileEntity::findInventories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
||||
BlockRayTraceResult hit) {
|
||||
if (worldIn.isRemote)
|
||||
return true;
|
||||
|
||||
if (worldIn.isRemote) {
|
||||
return true;
|
||||
} else {
|
||||
SchematicannonTileEntity te = (SchematicannonTileEntity) worldIn.getTileEntity(pos);
|
||||
if (te != null)
|
||||
if (AllItems.BLUEPRINT.typeOf(player.getHeldItemMainhand())
|
||||
&& te.inventory.getStackInSlot(0).isEmpty()) {
|
||||
te.inventory.setStackInSlot(0, player.getHeldItemMainhand());
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
|
||||
}
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
|
||||
return true;
|
||||
}
|
||||
withTileEntityDo(worldIn, pos,
|
||||
te -> NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (worldIn.getTileEntity(pos) == null)
|
||||
if (!state.hasTileEntity() || state.getBlock() == newState.getBlock())
|
||||
return;
|
||||
|
||||
SchematicannonTileEntity te = (SchematicannonTileEntity) worldIn.getTileEntity(pos);
|
||||
for (int slot = 0; slot < te.inventory.getSlots(); slot++) {
|
||||
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(),
|
||||
te.inventory.getStackInSlot(slot));
|
||||
}
|
||||
|
||||
if (state.hasTileEntity() && state.getBlock() != newState.getBlock()) {
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
withTileEntityDo(worldIn, pos, te -> ItemHelper.dropContents(worldIn, pos, te.inventory));
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<SchematicannonTileEntity> getTileEntityClass() {
|
||||
return SchematicannonTileEntity.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.inventory.container.Container;
|
|||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
public class SchematicannonContainer extends Container {
|
||||
|
@ -21,9 +22,12 @@ public class SchematicannonContainer extends Container {
|
|||
super(AllContainers.SCHEMATICANNON.type, id);
|
||||
player = inv.player;
|
||||
ClientWorld world = Minecraft.getInstance().world;
|
||||
this.te = (SchematicannonTileEntity) world.getTileEntity(buffer.readBlockPos());
|
||||
this.te.handleUpdateTag(buffer.readCompoundTag());
|
||||
init();
|
||||
TileEntity tileEntity = world.getTileEntity(buffer.readBlockPos());
|
||||
if (tileEntity instanceof SchematicannonTileEntity) {
|
||||
this.te = (SchematicannonTileEntity) tileEntity;
|
||||
this.te.handleUpdateTag(buffer.readCompoundTag());
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
public SchematicannonContainer(int id, PlayerInventory inv, SchematicannonTileEntity te) {
|
||||
|
@ -34,7 +38,6 @@ public class SchematicannonContainer extends Container {
|
|||
}
|
||||
|
||||
protected void init() {
|
||||
|
||||
int x = 20;
|
||||
int y = 0;
|
||||
|
||||
|
|
|
@ -50,48 +50,45 @@ public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
|||
context.get().enqueueWork(() -> {
|
||||
ServerPlayerEntity player = context.get().getSender();
|
||||
World world = player.world;
|
||||
|
||||
if (world == null || world.getTileEntity(pos) == null)
|
||||
if (world == null)
|
||||
return;
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (tileEntity instanceof SchematicannonTileEntity) {
|
||||
if (!(tileEntity instanceof SchematicannonTileEntity))
|
||||
return;
|
||||
|
||||
SchematicannonTileEntity te = (SchematicannonTileEntity) tileEntity;
|
||||
switch (option) {
|
||||
case DONT_REPLACE:
|
||||
case REPLACE_ANY:
|
||||
case REPLACE_EMPTY:
|
||||
case REPLACE_SOLID:
|
||||
te.replaceMode = option.ordinal();
|
||||
break;
|
||||
case SKIP_MISSING:
|
||||
te.skipMissing = set;
|
||||
break;
|
||||
case SKIP_TILES:
|
||||
te.replaceTileEntities = set;
|
||||
break;
|
||||
|
||||
case PLAY:
|
||||
te.state = State.RUNNING;
|
||||
te.statusMsg = "running";
|
||||
break;
|
||||
case PAUSE:
|
||||
te.state = State.PAUSED;
|
||||
te.statusMsg = "paused";
|
||||
break;
|
||||
case STOP:
|
||||
te.state = State.STOPPED;
|
||||
te.statusMsg = "stopped";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
te.sendUpdate = true;
|
||||
SchematicannonTileEntity te = (SchematicannonTileEntity) tileEntity;
|
||||
switch (option) {
|
||||
case DONT_REPLACE:
|
||||
case REPLACE_ANY:
|
||||
case REPLACE_EMPTY:
|
||||
case REPLACE_SOLID:
|
||||
te.replaceMode = option.ordinal();
|
||||
break;
|
||||
case SKIP_MISSING:
|
||||
te.skipMissing = set;
|
||||
break;
|
||||
case SKIP_TILES:
|
||||
te.replaceTileEntities = set;
|
||||
break;
|
||||
|
||||
case PLAY:
|
||||
te.state = State.RUNNING;
|
||||
te.statusMsg = "running";
|
||||
break;
|
||||
case PAUSE:
|
||||
te.state = State.PAUSED;
|
||||
te.statusMsg = "paused";
|
||||
break;
|
||||
case STOP:
|
||||
te.state = State.STOPPED;
|
||||
te.statusMsg = "stopped";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
te.sendUpdate = true;
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue