Re-add the Constructor

This commit is contained in:
raoulvdberge
2019-10-24 15:29:07 +02:00
parent 1ad1cfa330
commit 2b5e0a74e0
28 changed files with 1113 additions and 608 deletions

View File

@@ -60,6 +60,7 @@ public class ClientSetup {
new ResourceLocation(RS.ID, "block/security_manager/cutouts/right_connected")
));
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "wireless_transmitter"), (base, registry) -> new FullbrightBakedModel(base, new ResourceLocation(RS.ID, "block/wireless_transmitter/cutouts/connected")));
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "constructor"), (base, registry) -> new FullbrightBakedModel(base, new ResourceLocation(RS.ID, "block/constructor/cutouts/connected")));
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "disk_drive"), (base, registry) -> new FullbrightBakedModel(
new DiskDriveBakedModel(
@@ -132,6 +133,7 @@ public class ClientSetup {
ScreenManager.registerFactory(RSContainers.FLUID_INTERFACE, FluidInterfaceScreen::new);
ScreenManager.registerFactory(RSContainers.WIRELESS_TRANSMITTER, WirelessTransmitterScreen::new);
ScreenManager.registerFactory(RSContainers.STORAGE_MONITOR, StorageMonitorScreen::new);
ScreenManager.registerFactory(RSContainers.CONSTRUCTOR, ConstructorScreen::new);
ClientRegistry.registerKeyBinding(RSKeyBindings.OPEN_WIRELESS_GRID);
ClientRegistry.registerKeyBinding(RSKeyBindings.OPEN_WIRELESS_FLUID_GRID);

View File

@@ -130,6 +130,7 @@ public final class RS {
API.instance().getNetworkNodeRegistry().add(FluidInterfaceNetworkNode.ID, (tag, world, pos) -> readAndReturn(tag, new FluidInterfaceNetworkNode(world, pos)));
API.instance().getNetworkNodeRegistry().add(WirelessTransmitterNetworkNode.ID, (tag, world, pos) -> readAndReturn(tag, new WirelessTransmitterNetworkNode(world, pos)));
API.instance().getNetworkNodeRegistry().add(StorageMonitorNetworkNode.ID, (tag, world, pos) -> readAndReturn(tag, new StorageMonitorNetworkNode(world, pos)));
API.instance().getNetworkNodeRegistry().add(ConstructorNetworkNode.ID, (tag, world, pos) -> readAndReturn(tag, new ConstructorNetworkNode(world, pos)));
API.instance().getGridManager().add(GridBlockGridFactory.ID, new GridBlockGridFactory());
API.instance().getGridManager().add(WirelessGridGridFactory.ID, new WirelessGridGridFactory());
@@ -185,6 +186,7 @@ public final class RS {
e.getRegistry().register(new FluidInterfaceBlock());
e.getRegistry().register(new WirelessTransmitterBlock());
e.getRegistry().register(new StorageMonitorBlock());
e.getRegistry().register(new ConstructorBlock());
}
@SubscribeEvent
@@ -222,6 +224,7 @@ public final class RS {
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(FluidInterfaceTile::new, RSBlocks.FLUID_INTERFACE).build(null).setRegistryName(RS.ID, "fluid_interface")));
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(WirelessTransmitterTile::new, RSBlocks.WIRELESS_TRANSMITTER).build(null).setRegistryName(RS.ID, "wireless_transmitter")));
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(StorageMonitorTile::new, RSBlocks.STORAGE_MONITOR).build(null).setRegistryName(RS.ID, "storage_monitor")));
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(ConstructorTile::new, RSBlocks.CONSTRUCTOR).build(null).setRegistryName(RS.ID, "constructor")));
}
private <T extends TileEntity> TileEntityType<T> registerTileDataParameters(TileEntityType<T> t) {
@@ -251,6 +254,7 @@ public final class RS {
e.getRegistry().register(IForgeContainerType.create(new PositionalTileContainerFactory<FluidInterfaceContainer, FluidInterfaceTile>((windowId, inv, tile) -> new FluidInterfaceContainer(tile, inv.player, windowId))).setRegistryName(RS.ID, "fluid_interface"));
e.getRegistry().register(IForgeContainerType.create(new PositionalTileContainerFactory<WirelessTransmitterContainer, WirelessTransmitterTile>((windowId, inv, tile) -> new WirelessTransmitterContainer(tile, inv.player, windowId))).setRegistryName(RS.ID, "wireless_transmitter"));
e.getRegistry().register(IForgeContainerType.create(new PositionalTileContainerFactory<StorageMonitorContainer, StorageMonitorTile>((windowId, inv, tile) -> new StorageMonitorContainer(tile, inv.player, windowId))).setRegistryName(RS.ID, "storage_monitor"));
e.getRegistry().register(IForgeContainerType.create(new PositionalTileContainerFactory<ConstructorContainer, ConstructorTile>((windowId, inv, tile) -> new ConstructorContainer(tile, inv.player, windowId))).setRegistryName(RS.ID, "constructor"));
}
@SubscribeEvent
@@ -330,6 +334,7 @@ public final class RS {
e.getRegistry().register(BlockUtils.createBlockItemFor(RSBlocks.FLUID_INTERFACE));
e.getRegistry().register(new WirelessTransmitterBlockItem());
e.getRegistry().register(BlockUtils.createBlockItemFor(RSBlocks.STORAGE_MONITOR));
e.getRegistry().register(BlockUtils.createBlockItemFor(RSBlocks.CONSTRUCTOR));
e.getRegistry().register(new WirelessGridItem(WirelessGridItem.Type.NORMAL));
e.getRegistry().register(new WirelessGridItem(WirelessGridItem.Type.CREATIVE));

View File

@@ -68,9 +68,10 @@ public final class RSBlocks {
public static final WirelessTransmitterBlock WIRELESS_TRANSMITTER = null;
@ObjectHolder(RS.ID + ":storage_monitor")
public static final StorageMonitorBlock STORAGE_MONITOR = null;
@ObjectHolder(RS.ID + ":constructor")
public static final ConstructorBlock CONSTRUCTOR = null;
public static final BlockDestructor DESTRUCTOR = new BlockDestructor();
public static final BlockConstructor CONSTRUCTOR = new BlockConstructor();
public static final BlockCraftingMonitor CRAFTING_MONITOR = new BlockCraftingMonitor();
public static final BlockCrafter CRAFTER = new BlockCrafter();
public static final BlockDiskManipulator DISK_MANIPULATOR = new BlockDiskManipulator();

View File

@@ -39,6 +39,8 @@ public final class RSContainers {
public static final ContainerType<WirelessTransmitterContainer> WIRELESS_TRANSMITTER = null;
@ObjectHolder(RS.ID + ":storage_monitor")
public static final ContainerType<StorageMonitorContainer> STORAGE_MONITOR = null;
@ObjectHolder(RS.ID + ":constructor")
public static final ContainerType<ConstructorContainer> CONSTRUCTOR = null;
//@ObjectHolder(RS.ID + ":crafter")
public static final ContainerType<CrafterContainer> CRAFTER = null;
@@ -48,8 +50,6 @@ public final class RSContainers {
public static final ContainerType<CraftingMonitorContainer> CRAFTING_MONITOR = null;
//@ObjectHolder(RS.ID + ":destructor")
public static final ContainerType<DestructorContainer> DESTRUCTOR = null;
//@ObjectHolder(RS.ID + ":constructor")
public static final ContainerType<ConstructorContainer> CONSTRUCTOR = null;
//@ObjectHolder(RS.ID + ":disk_manipulator")
public static final ContainerType<DiskManipulatorContainer> DISK_MANIPULATOR = null;
}

View File

@@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage;
public class RSOldConfig {
//region Energy
public int constructorUsage;
public int crafterUsage;
public int crafterPerPatternUsage;
public int craftingMonitorUsage;
@@ -40,7 +39,6 @@ public class RSOldConfig {
/*private void loadConfig() {
//region Energy
constructorUsage = config.getInt("constructor", ENERGY, 1, 0, Integer.MAX_VALUE, "The energy used by Constructors");
crafterUsage = config.getInt("crafter", ENERGY, 2, 0, Integer.MAX_VALUE, "The base energy used by Crafters");
crafterPerPatternUsage = config.getInt("crafterPerPattern", ENERGY, 1, 0, Integer.MAX_VALUE, "The additional energy used per Pattern in a Crafter");
craftingMonitorUsage = config.getInt("craftingMonitor", ENERGY, 2, 0, Integer.MAX_VALUE, "The energy used by Crafting Monitors");

View File

@@ -68,6 +68,8 @@ public class RSTiles {
public static final TileEntityType<WirelessTransmitterTile> WIRELESS_TRANSMITTER = null;
@ObjectHolder(RS.ID + ":storage_monitor")
public static final TileEntityType<StorageMonitorTile> STORAGE_MONITOR = null;
@ObjectHolder(RS.ID + ":constructor")
public static final TileEntityType<ConstructorTile> CONSTRUCTOR = null;
//@ObjectHolder(RS.ID + ":portable_grid")
public static final TileEntityType<TilePortableGrid> PORTABLE_GRID = null;
@@ -81,6 +83,4 @@ public class RSTiles {
public static final TileEntityType<TileCraftingMonitor> CRAFTING_MONITOR = null;
//@ObjectHolder(RS.ID + ":destructor")
public static final TileEntityType<TileDestructor> DESTRUCTOR = null;
//@ObjectHolder(RS.ID + ":constructor")
public static final TileEntityType<TileConstructor> CONSTRUCTOR = null;
}

View File

@@ -0,0 +1,345 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.mojang.authlib.GameProfile;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
import com.raoulvdberge.refinedstorage.inventory.item.BaseItemHandler;
import com.raoulvdberge.refinedstorage.inventory.item.UpgradeItemHandler;
import com.raoulvdberge.refinedstorage.inventory.listener.NetworkNodeFluidInventoryListener;
import com.raoulvdberge.refinedstorage.inventory.listener.NetworkNodeInventoryListener;
import com.raoulvdberge.refinedstorage.item.UpgradeItem;
import com.raoulvdberge.refinedstorage.tile.ConstructorTile;
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
import com.raoulvdberge.refinedstorage.tile.config.IType;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.dispenser.Position;
import net.minecraft.entity.item.FireworkRocketEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.UUID;
public class ConstructorNetworkNode extends NetworkNode implements IComparable, IType {
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "constructor");
private static final String NBT_COMPARE = "Compare";
private static final String NBT_TYPE = "Type";
private static final String NBT_DROP = "Drop";
private static final String NBT_FLUID_FILTERS = "FluidFilters";
private static final int BASE_SPEED = 20;
private BaseItemHandler itemFilters = new BaseItemHandler(1).addListener(new NetworkNodeInventoryListener(this));
private FluidInventory fluidFilters = new FluidInventory(1)
.addListener(new NetworkNodeFluidInventoryListener(this));
private UpgradeItemHandler upgrades = (UpgradeItemHandler) new UpgradeItemHandler(4, UpgradeItem.Type.SPEED, UpgradeItem.Type.CRAFTING, UpgradeItem.Type.STACK)
.addListener(new NetworkNodeInventoryListener(this));
private int compare = IComparer.COMPARE_NBT;
private int type = IType.ITEMS;
private boolean drop = false;
public ConstructorNetworkNode(World world, BlockPos pos) {
super(world, pos);
}
@Override
public int getEnergyUsage() {
return RS.SERVER_CONFIG.getConstructor().getUsage() + upgrades.getEnergyUsage();
}
@Override
public void update() {
super.update();
if (canUpdate() && ticks % upgrades.getSpeed(BASE_SPEED, 4) == 0) {
if (type == IType.ITEMS && !itemFilters.getStackInSlot(0).isEmpty()) {
ItemStack stack = itemFilters.getStackInSlot(0);
if (drop) {
extractAndDropItem(stack);
} else if (stack.getItem() == Items.FIREWORK_ROCKET) {
extractAndSpawnFireworks(stack);
} else if (stack.getItem() instanceof BlockItem) {
extractAndPlaceBlock(stack);
}
} else if (type == IType.FLUIDS && !fluidFilters.getFluid(0).isEmpty()) {
extractAndPlaceFluid(fluidFilters.getFluid(0));
}
}
}
private void extractAndPlaceFluid(FluidStack stack) {
BlockPos front = pos.offset(getDirection());
if (network.extractFluid(stack, FluidAttributes.BUCKET_VOLUME, compare, Action.SIMULATE).getAmount() < FluidAttributes.BUCKET_VOLUME) {
if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
network.getCraftingManager().request(this, stack, FluidAttributes.BUCKET_VOLUME);
}
} else if (world.isAirBlock(front) && FluidUtil.tryPlaceFluid(getFakePlayer(), world, Hand.MAIN_HAND, front, new NetworkFluidHandler(StackUtils.copy(stack, FluidAttributes.BUCKET_VOLUME)), stack)) {
// We manually have to check world.isAirBlock in the else if statement because tryPlaceFluid ignores this.
network.extractFluid(stack, FluidAttributes.BUCKET_VOLUME, Action.PERFORM);
}
}
private void extractAndPlaceBlock(ItemStack stack) {
if (!network.extractItem(stack, 1, compare, Action.SIMULATE).isEmpty()) {
BlockItemUseContext ctx = new ConstructorBlockItemUseContext(
world,
getFakePlayer(),
Hand.MAIN_HAND,
ItemHandlerHelper.copyStackWithSize(stack, 1),
new BlockRayTraceResult(Vec3d.ZERO, getDirection(), pos, false)
);
ActionResultType result = ForgeHooks.onPlaceItemIntoWorld(ctx);
if (result == ActionResultType.SUCCESS) {
network.extractItem(stack, 1, Action.PERFORM);
}
} else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
ItemStack craft = itemFilters.getStackInSlot(0);
network.getCraftingManager().request(this, craft, 1);
}
}
private void extractAndDropItem(ItemStack stack) {
ItemStack took = network.extractItem(stack, upgrades.getStackInteractCount(), Action.PERFORM);
if (!took.isEmpty()) {
DefaultDispenseItemBehavior.doDispense(world, took, 6, getDirection(), new Position(getDispensePositionX(), getDispensePositionY(), getDispensePositionZ()));
} else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
network.getCraftingManager().request(this, stack, 1);
}
}
private void extractAndSpawnFireworks(ItemStack stack) {
ItemStack took = network.extractItem(stack, 1, Action.PERFORM);
if (!took.isEmpty()) {
world.addEntity(new FireworkRocketEntity(world, getDispensePositionX(), getDispensePositionY(), getDispensePositionZ(), took));
}
}
private FakePlayer getFakePlayer() {
ServerWorld world = (ServerWorld) this.world;
UUID owner = getOwner();
if (owner != null) {
GameProfile profile = world.getServer().getPlayerProfileCache().getProfileByUUID(owner);
if (profile != null) {
return FakePlayerFactory.get(world, profile);
}
}
return FakePlayerFactory.getMinecraft(world);
}
// @Volatile: From BlockDispenser#getDispensePosition
private double getDispensePositionX() {
return (double) pos.getX() + 0.5D + 0.8D * (double) getDirection().getXOffset();
}
// @Volatile: From BlockDispenser#getDispensePosition
private double getDispensePositionY() {
return (double) pos.getY() + (getDirection() == Direction.DOWN ? 0.45D : 0.5D) + 0.8D * (double) getDirection().getYOffset();
}
// @Volatile: From BlockDispenser#getDispensePosition
private double getDispensePositionZ() {
return (double) pos.getZ() + 0.5D + 0.8D * (double) getDirection().getZOffset();
}
@Override
public int getCompare() {
return compare;
}
@Override
public void setCompare(int compare) {
this.compare = compare;
markDirty();
}
@Override
public void read(CompoundNBT tag) {
super.read(tag);
StackUtils.readItems(upgrades, 1, tag);
}
@Override
public ResourceLocation getId() {
return ID;
}
@Override
public CompoundNBT write(CompoundNBT tag) {
super.write(tag);
StackUtils.writeItems(upgrades, 1, tag);
return tag;
}
@Override
public CompoundNBT writeConfiguration(CompoundNBT tag) {
super.writeConfiguration(tag);
tag.putInt(NBT_COMPARE, compare);
tag.putInt(NBT_TYPE, type);
tag.putBoolean(NBT_DROP, drop);
StackUtils.writeItems(itemFilters, 0, tag);
tag.put(NBT_FLUID_FILTERS, fluidFilters.writeToNbt());
return tag;
}
@Override
public void readConfiguration(CompoundNBT tag) {
super.readConfiguration(tag);
if (tag.contains(NBT_COMPARE)) {
compare = tag.getInt(NBT_COMPARE);
}
if (tag.contains(NBT_TYPE)) {
type = tag.getInt(NBT_TYPE);
}
if (tag.contains(NBT_DROP)) {
drop = tag.getBoolean(NBT_DROP);
}
StackUtils.readItems(itemFilters, 0, tag);
if (tag.contains(NBT_FLUID_FILTERS)) {
fluidFilters.readFromNbt(tag.getCompound(NBT_FLUID_FILTERS));
}
}
public boolean isDrop() {
return drop;
}
public void setDrop(boolean drop) {
this.drop = drop;
}
public IItemHandler getUpgrades() {
return upgrades;
}
@Override
public IItemHandler getDrops() {
return upgrades;
}
@Override
public int getType() {
return world.isRemote ? ConstructorTile.TYPE.getValue() : type;
}
@Override
public void setType(int type) {
this.type = type;
markDirty();
}
@Override
public IItemHandlerModifiable getItemFilters() {
return itemFilters;
}
@Override
public FluidInventory getFluidFilters() {
return fluidFilters;
}
private class NetworkFluidHandler implements IFluidHandler {
private FluidStack resource;
public NetworkFluidHandler(FluidStack resource) {
this.resource = resource;
}
@Override
public int getTanks() {
throw new RuntimeException("Cannot be called");
}
@Nonnull
@Override
public FluidStack getFluidInTank(int tank) {
throw new RuntimeException("Cannot be called");
}
@Override
public int getTankCapacity(int tank) {
throw new RuntimeException("Cannot be called");
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
throw new RuntimeException("Cannot be called");
}
@Override
public int fill(FluidStack resource, FluidAction action) {
throw new RuntimeException("Cannot be called");
}
@Nonnull
@Override
public FluidStack drain(FluidStack resource, FluidAction action) {
return network.extractFluid(resource, resource.getAmount(), action == FluidAction.SIMULATE ? Action.SIMULATE : Action.PERFORM);
}
@Nonnull
@Override
public FluidStack drain(int maxDrain, FluidAction action) {
return network.extractFluid(resource, resource.getAmount(), action == FluidAction.SIMULATE ? Action.SIMULATE : Action.PERFORM);
}
}
private class ConstructorBlockItemUseContext extends BlockItemUseContext {
public ConstructorBlockItemUseContext(World worldIn, @Nullable PlayerEntity playerIn, Hand handIn, ItemStack stackIn, BlockRayTraceResult rayTraceResultIn) {
super(worldIn, playerIn, handIn, stackIn, rayTraceResultIn);
}
}
}

View File

@@ -1,379 +0,0 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
import com.mojang.authlib.GameProfile;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.Action;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.container.slot.filter.FilterSlot;
import com.raoulvdberge.refinedstorage.inventory.fluid.FluidInventory;
import com.raoulvdberge.refinedstorage.inventory.item.BaseItemHandler;
import com.raoulvdberge.refinedstorage.inventory.item.UpgradeItemHandler;
import com.raoulvdberge.refinedstorage.inventory.listener.NetworkNodeFluidInventoryListener;
import com.raoulvdberge.refinedstorage.inventory.listener.NetworkNodeInventoryListener;
import com.raoulvdberge.refinedstorage.item.UpgradeItem;
import com.raoulvdberge.refinedstorage.tile.TileConstructor;
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
import com.raoulvdberge.refinedstorage.tile.config.IType;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.dispenser.Position;
import net.minecraft.entity.item.FireworkRocketEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import java.util.UUID;
public class NetworkNodeConstructor extends NetworkNode implements IComparable, IType {
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "constructor");
private static final String NBT_COMPARE = "Compare";
private static final String NBT_TYPE = "Type";
private static final String NBT_DROP = "Drop";
private static final String NBT_FLUID_FILTERS = "FluidFilters";
private static final int BASE_SPEED = 20;
private BaseItemHandler itemFilters = new BaseItemHandler(1).addListener(new NetworkNodeInventoryListener(this));
private FluidInventory fluidFilters = new FluidInventory(1).addListener(new NetworkNodeFluidInventoryListener(this));
private UpgradeItemHandler upgrades = (UpgradeItemHandler) new UpgradeItemHandler(4 /* TODO, ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_CRAFTING, ItemUpgrade.TYPE_STACK*/).addListener(new NetworkNodeInventoryListener(this));
private int compare = IComparer.COMPARE_NBT;
private int type = IType.ITEMS;
private boolean drop = false;
public NetworkNodeConstructor(World world, BlockPos pos) {
super(world, pos);
}
@Override
public int getEnergyUsage() {
return RS.INSTANCE.config.constructorUsage + upgrades.getEnergyUsage();
}
@Override
public void update() {
super.update();
if (canUpdate() && ticks % upgrades.getSpeed(BASE_SPEED, 4) == 0) {
if (type == IType.ITEMS && !itemFilters.getStackInSlot(0).isEmpty()) {
ItemStack item = itemFilters.getStackInSlot(0);
BlockState block = FilterSlot.getBlockState(world, pos.offset(getDirection()), item);
if (block != null) {
if (drop) {
dropItem();
} else {
placeBlock();
}
} else {
if (item.getItem() == Items.FIREWORK_ROCKET && !drop) {
ItemStack took = network.extractItem(item, 1, Action.PERFORM);
if (!took.isEmpty()) {
world.addEntity(new FireworkRocketEntity(world, getDispensePositionX(), getDispensePositionY(), getDispensePositionZ(), took));
}
} else {
dropItem();
}
}
} else if (type == IType.FLUIDS && !fluidFilters.getFluid(0).isEmpty()) {
/*TODO FluidStack stack = fluidFilters.getFluid(0);
if (stack != null && stack.getFluid().getAttributes().canBePlacedInWorld()) {
BlockPos front = pos.offset(getDirection());
Block block = stack.getFluid().getAttributes();
if (world.isAirBlock(front) && block.canPlaceBlockAt(world, front)) {
FluidStack stored = network.getFluidStorageCache().getList().get(stack, compare);
if (stored != null && stored.amount >= Fluid.BUCKET_VOLUME) {
FluidStack took = network.extractFluid(stack, Fluid.BUCKET_VOLUME, compare, Action.PERFORM);
if (took != null) {
IBlockState state = block.getDefaultState();
if (state.getBlock() == Blocks.WATER) {
state = Blocks.FLOWING_WATER.getDefaultState();
} else if (state.getBlock() == Blocks.LAVA) {
state = Blocks.FLOWING_LAVA.getDefaultState();
}
if (!canPlace(front, state)) {
return;
}
world.setBlockState(front, state, 1 | 2);
}
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_CRAFTING)) {
network.getCraftingManager().request(this, stack, Fluid.BUCKET_VOLUME);
}
}
}*/
}
}
}
private FakePlayer getFakePlayer() {
ServerWorld world = (ServerWorld) this.world;
UUID owner = getOwner();
if (owner != null) {
PlayerProfileCache profileCache = world.getServer().getPlayerProfileCache();
GameProfile profile = profileCache.getProfileByUUID(owner);
if (profile != null) {
return FakePlayerFactory.get(world, profile);
}
}
return FakePlayerFactory.getMinecraft(world);
}
private boolean canPlace(BlockPos pos, BlockState state) {
BlockEvent.EntityPlaceEvent e = new BlockEvent.EntityPlaceEvent(new BlockSnapshot(world, pos, state), world.getBlockState(pos), getFakePlayer());
return !MinecraftForge.EVENT_BUS.post(e);
}
private void placeBlock() {
BlockPos front = pos.offset(getDirection());
ItemStack item = itemFilters.getStackInSlot(0);
ItemStack took = network.extractItem(item, 1, compare, Action.SIMULATE);
if (!took.isEmpty()) {
BlockState state = FilterSlot.getBlockState(world, front, took);
// TODO if (state != null && world.isAirBlock(front) && state.getBlock().canPlaceBlockAt(world, front)) {
if (false) {
// TODO state = state.getBlock().getStateForPlacement(world, front, getDirection(), 0.5F, 0.5F, 0.5F, took.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) world), EnumHand.MAIN_HAND);
if (!canPlace(front, state)) {
return;
}
took = network.extractItem(item, 1, compare, Action.PERFORM);
if (!took.isEmpty()) {
if (item.getItem() instanceof BlockItem) {
/*((BlockItem) item.getItem()).tryPlace(new BlockItemUseContext(
took,
getFakePlayer(),
world,
front,
getDirection(),
0,
0,
0,
state
)); TODO! */
} else {
world.setBlockState(front, state, 1 | 2);
state.getBlock().onBlockPlacedBy(world, front, state, FakePlayerFactory.getMinecraft((ServerWorld) world), took);
}
// From ItemBlock#onItemUse
SoundType blockSound = state.getBlock().getSoundType(state, world, pos, null);
world.playSound(null, front, blockSound.getPlaceSound(), SoundCategory.BLOCKS, (blockSound.getVolume() + 1.0F) / 2.0F, blockSound.getPitch() * 0.8F);
/* TODO
if (state.getBlock() == Blocks.SKULL) {
world.setBlockState(front, world.getBlockState(front).withProperty(BlockSkull.FACING, getDirection()));
TileEntity tile = world.getTileEntity(front);
if (tile instanceof SkullTileEntity) {
SkullTileEntity skullTile = (SkullTileEntity) tile;
if (item.getItemDamage() == 3) {
GameProfile playerInfo = null;
if (item.hasTagCompound()) {
CompoundNBT tag = item.getTagCompound();
if (tag.contains("SkullOwner", 10)) {
playerInfo = NBTUtil.readGameProfileFromNBT(tag.getCompound("SkullOwner"));
} else if (tag.contains("SkullOwner", 8) && !tag.getString("SkullOwner").isEmpty()) {
playerInfo = new GameProfile(null, tag.getString("SkullOwner"));
}
}
skullTile.setPlayerProfile(playerInfo);
} else {
skullTile.setType(item.getMetadata());
}
Blocks.SKULL.checkWitherSpawn(world, front, skullTile);
}
}*/
}
}
} else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
ItemStack craft = itemFilters.getStackInSlot(0);
network.getCraftingManager().request(this, craft, 1);
}
}
private void dropItem() {
ItemStack took = network.extractItem(itemFilters.getStackInSlot(0), upgrades.getStackInteractCount(), Action.PERFORM);
if (!took.isEmpty()) {
DefaultDispenseItemBehavior.doDispense(world, took, 6, getDirection(), new Position(getDispensePositionX(), getDispensePositionY(), getDispensePositionZ()));
} else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
ItemStack craft = itemFilters.getStackInSlot(0);
network.getCraftingManager().request(this, craft, 1);
}
}
// From BlockDispenser#getDispensePosition
private double getDispensePositionX() {
return (double) pos.getX() + 0.5D + 0.8D * (double) getDirection().getXOffset();
}
// From BlockDispenser#getDispensePosition
private double getDispensePositionY() {
return (double) pos.getY() + (getDirection() == Direction.DOWN ? 0.45D : 0.5D) + 0.8D * (double) getDirection().getYOffset();
}
// From BlockDispenser#getDispensePosition
private double getDispensePositionZ() {
return (double) pos.getZ() + 0.5D + 0.8D * (double) getDirection().getZOffset();
}
@Override
public int getCompare() {
return compare;
}
@Override
public void setCompare(int compare) {
this.compare = compare;
markDirty();
}
@Override
public void read(CompoundNBT tag) {
super.read(tag);
StackUtils.readItems(upgrades, 1, tag);
}
@Override
public ResourceLocation getId() {
return ID;
}
@Override
public CompoundNBT write(CompoundNBT tag) {
super.write(tag);
StackUtils.writeItems(upgrades, 1, tag);
return tag;
}
@Override
public CompoundNBT writeConfiguration(CompoundNBT tag) {
super.writeConfiguration(tag);
tag.putInt(NBT_COMPARE, compare);
tag.putInt(NBT_TYPE, type);
tag.putBoolean(NBT_DROP, drop);
StackUtils.writeItems(itemFilters, 0, tag);
tag.put(NBT_FLUID_FILTERS, fluidFilters.writeToNbt());
return tag;
}
@Override
public void readConfiguration(CompoundNBT tag) {
super.readConfiguration(tag);
if (tag.contains(NBT_COMPARE)) {
compare = tag.getInt(NBT_COMPARE);
}
if (tag.contains(NBT_TYPE)) {
type = tag.getInt(NBT_TYPE);
}
if (tag.contains(NBT_DROP)) {
drop = tag.getBoolean(NBT_DROP);
}
StackUtils.readItems(itemFilters, 0, tag);
if (tag.contains(NBT_FLUID_FILTERS)) {
fluidFilters.readFromNbt(tag.getCompound(NBT_FLUID_FILTERS));
}
}
public boolean isDrop() {
return drop;
}
public void setDrop(boolean drop) {
this.drop = drop;
}
public IItemHandler getUpgrades() {
return upgrades;
}
@Override
public IItemHandler getDrops() {
return upgrades;
}
@Override
public int getType() {
return world.isRemote ? TileConstructor.TYPE.getValue() : type;
}
@Override
public void setType(int type) {
this.type = type;
markDirty();
}
@Override
public IItemHandlerModifiable getItemFilters() {
return itemFilters;
}
@Override
public FluidInventory getFluidFilters() {
return fluidFilters;
}
}

View File

@@ -1,71 +0,0 @@
package com.raoulvdberge.refinedstorage.block;
public class BlockConstructor extends CableBlock {
/* TODO
public BlockConstructor() {
super(createBuilder("constructor").tileEntity(TileConstructor::new).create());
}
@Override
@OnlyIn(Dist.CLIENT)
public void registerModels(IModelRegistration modelRegistration) {
modelRegistration.setModel(this, 0, new ModelResourceLocation(info.getId(), "connected=false,direction=north,down=false,east=true,north=false,south=false,up=false,west=true"));
registerCoverAndFullbright(modelRegistration, RS.ID + ":blocks/constructor/cutouts/connected");
}
@Override
@Nullable
public BlockDirection getDirection() {
return BlockDirection.ANY;
}
@Override
public List<CollisionGroup> getCollisions(TileEntity tile, BlockState state) {
List<CollisionGroup> groups = super.getCollisions(tile, state);
switch (state.getValue(getDirection().getProperty())) {
case NORTH:
groups.add(ConstantsCable.HOLDER_NORTH);
groups.add(ConstantsConstructor.HEAD_NORTH);
break;
case EAST:
groups.add(ConstantsCable.HOLDER_EAST);
groups.add(ConstantsConstructor.HEAD_EAST);
break;
case SOUTH:
groups.add(ConstantsCable.HOLDER_SOUTH);
groups.add(ConstantsConstructor.HEAD_SOUTH);
break;
case WEST:
groups.add(ConstantsCable.HOLDER_WEST);
groups.add(ConstantsConstructor.HEAD_WEST);
break;
case UP:
groups.add(ConstantsCable.HOLDER_UP);
groups.add(ConstantsConstructor.HEAD_UP);
break;
case DOWN:
groups.add(ConstantsCable.HOLDER_DOWN);
groups.add(ConstantsConstructor.HEAD_DOWN);
break;
}
return groups;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction side, float hitX, float hitY, float hitZ) {
if (!canAccessGui(state, world, pos, hitX, hitY, hitZ)) {
return false;
}
return openNetworkGui(RSGui.CONSTRUCTOR, player, world, pos, side);
}
@Override
public boolean hasConnectedState() {
return true;
}
*/
}

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.block.info.BlockDirection;
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
import com.raoulvdberge.refinedstorage.tile.CableTile;
import com.raoulvdberge.refinedstorage.util.BlockUtils;
@@ -29,6 +30,13 @@ public class CableBlock extends NodeBlock {
private static final BooleanProperty UP = BooleanProperty.create("up");
private static final BooleanProperty DOWN = BooleanProperty.create("down");
protected static final VoxelShape HOLDER_NORTH = makeCuboidShape(7, 7, 2, 9, 9, 6);
protected static final VoxelShape HOLDER_EAST = makeCuboidShape(10, 7, 7, 14, 9, 9);
protected static final VoxelShape HOLDER_SOUTH = makeCuboidShape(7, 7, 10, 9, 9, 14);
protected static final VoxelShape HOLDER_WEST = makeCuboidShape(2, 7, 7, 6, 9, 9);
protected static final VoxelShape HOLDER_UP = makeCuboidShape(7, 10, 7, 9, 14, 9);
protected static final VoxelShape HOLDER_DOWN = makeCuboidShape(7, 2, 7, 9, 6, 9);
private static final VoxelShape SHAPE_CORE = makeCuboidShape(6, 6, 6, 10, 10, 10);
private static final VoxelShape SHAPE_NORTH = makeCuboidShape(6, 6, 0, 10, 10, 6);
private static final VoxelShape SHAPE_EAST = makeCuboidShape(10, 6, 6, 16, 10, 10);
@@ -94,7 +102,11 @@ public class CableBlock extends NodeBlock {
return getState(getDefaultState(), ctx.getWorld(), ctx.getPos());
}
private static boolean hasNode(World world, BlockPos pos, Direction direction) {
private boolean hasNode(World world, BlockPos pos, BlockState state, Direction direction) {
if (getDirection() != BlockDirection.NONE && state.get(getDirection().getProperty()) == direction.getOpposite()) {
return false;
}
TileEntity tile = world.getTileEntity(pos);
if (tile == null) {
return false;
@@ -104,12 +116,12 @@ public class CableBlock extends NodeBlock {
}
private BlockState getState(BlockState currentState, World world, BlockPos pos) {
boolean north = hasNode(world, pos.offset(Direction.NORTH), Direction.SOUTH);
boolean east = hasNode(world, pos.offset(Direction.EAST), Direction.WEST);
boolean south = hasNode(world, pos.offset(Direction.SOUTH), Direction.NORTH);
boolean west = hasNode(world, pos.offset(Direction.WEST), Direction.EAST);
boolean up = hasNode(world, pos.offset(Direction.UP), Direction.DOWN);
boolean down = hasNode(world, pos.offset(Direction.DOWN), Direction.UP);
boolean north = hasNode(world, pos.offset(Direction.NORTH), currentState, Direction.SOUTH);
boolean east = hasNode(world, pos.offset(Direction.EAST), currentState, Direction.WEST);
boolean south = hasNode(world, pos.offset(Direction.SOUTH), currentState, Direction.NORTH);
boolean west = hasNode(world, pos.offset(Direction.WEST), currentState, Direction.EAST);
boolean up = hasNode(world, pos.offset(Direction.UP), currentState, Direction.DOWN);
boolean down = hasNode(world, pos.offset(Direction.DOWN), currentState, Direction.UP);
return currentState
.with(NORTH, north)

View File

@@ -0,0 +1,108 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.block.info.BlockDirection;
import com.raoulvdberge.refinedstorage.container.ConstructorContainer;
import com.raoulvdberge.refinedstorage.container.factory.PositionalTileContainerProvider;
import com.raoulvdberge.refinedstorage.tile.ConstructorTile;
import com.raoulvdberge.refinedstorage.util.BlockUtils;
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;
import javax.annotation.Nullable;
public class ConstructorBlock extends CableBlock {
private static final VoxelShape HEAD_NORTH = VoxelShapes.or(makeCuboidShape(2, 2, 0, 14, 14, 2), HOLDER_NORTH);
private static final VoxelShape HEAD_EAST = VoxelShapes.or(makeCuboidShape(14, 2, 2, 16, 14, 14), HOLDER_EAST);
private static final VoxelShape HEAD_SOUTH = VoxelShapes.or(makeCuboidShape(2, 2, 14, 14, 14, 16), HOLDER_SOUTH);
private static final VoxelShape HEAD_WEST = VoxelShapes.or(makeCuboidShape(0, 2, 2, 2, 14, 14), HOLDER_WEST);
private static final VoxelShape HEAD_DOWN = VoxelShapes.or(makeCuboidShape(2, 0, 2, 14, 2, 14), HOLDER_DOWN);
private static final VoxelShape HEAD_UP = VoxelShapes.or(makeCuboidShape(2, 14, 2, 14, 16, 14), HOLDER_UP);
public ConstructorBlock() {
super(BlockUtils.DEFAULT_GLASS_PROPERTIES);
this.setRegistryName(RS.ID, "constructor");
}
@Override
public BlockDirection getDirection() {
return BlockDirection.ANY;
}
@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new ConstructorTile();
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext ctx) {
VoxelShape shape = super.getShape(state, world, pos, ctx);
Direction direction = state.get(getDirection().getProperty());
if (direction == Direction.NORTH) {
shape = VoxelShapes.or(shape, HEAD_NORTH);
}
if (direction == Direction.EAST) {
shape = VoxelShapes.or(shape, HEAD_EAST);
}
if (direction == Direction.SOUTH) {
shape = VoxelShapes.or(shape, HEAD_SOUTH);
}
if (direction == Direction.WEST) {
shape = VoxelShapes.or(shape, HEAD_WEST);
}
if (direction == Direction.UP) {
shape = VoxelShapes.or(shape, HEAD_UP);
}
if (direction == Direction.DOWN) {
shape = VoxelShapes.or(shape, HEAD_DOWN);
}
return shape;
}
@Override
@SuppressWarnings("deprecation")
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (!world.isRemote) {
return NetworkUtils.attemptModify(world, pos, hit.getFace(), player, () -> NetworkHooks.openGui(
(ServerPlayerEntity) player,
new PositionalTileContainerProvider<ConstructorTile>(
new TranslationTextComponent("gui.refinedstorage.constructor"),
(tile, windowId, inventory, p) -> new ConstructorContainer(tile, player, windowId),
pos
),
pos
));
}
return true;
}
@Override
public boolean hasConnectedState() {
return true;
}
}

View File

@@ -26,12 +26,12 @@ import net.minecraftforge.fml.network.NetworkHooks;
import javax.annotation.Nullable;
public class ExternalStorageBlock extends CableBlock {
private static final VoxelShape HEAD_NORTH = makeCuboidShape(3, 3, 0, 13, 13, 2);
private static final VoxelShape HEAD_EAST = makeCuboidShape(14, 3, 3, 16, 13, 13);
private static final VoxelShape HEAD_SOUTH = makeCuboidShape(3, 3, 14, 13, 13, 16);
private static final VoxelShape HEAD_WEST = makeCuboidShape(0, 3, 3, 2, 13, 13);
private static final VoxelShape HEAD_UP = makeCuboidShape(3, 14, 3, 13, 16, 13);
private static final VoxelShape HEAD_DOWN = makeCuboidShape(3, 0, 3, 13, 2, 13);
private static final VoxelShape HEAD_NORTH = VoxelShapes.or(makeCuboidShape(3, 3, 0, 13, 13, 2), HOLDER_NORTH);
private static final VoxelShape HEAD_EAST = VoxelShapes.or(makeCuboidShape(14, 3, 3, 16, 13, 13), HOLDER_EAST);
private static final VoxelShape HEAD_SOUTH = VoxelShapes.or(makeCuboidShape(3, 3, 14, 13, 13, 16), HOLDER_SOUTH);
private static final VoxelShape HEAD_WEST = VoxelShapes.or(makeCuboidShape(0, 3, 3, 2, 13, 13), HOLDER_WEST);
private static final VoxelShape HEAD_UP = VoxelShapes.or(makeCuboidShape(3, 14, 3, 13, 16, 13), HOLDER_UP);
private static final VoxelShape HEAD_DOWN = VoxelShapes.or(makeCuboidShape(3, 0, 3, 13, 2, 13), HOLDER_DOWN);
public ExternalStorageBlock() {
super(BlockUtils.DEFAULT_GLASS_PROPERTIES);

View File

@@ -27,6 +27,7 @@ public class ServerConfig {
private StorageMonitor storageMonitor;
private WirelessGrid wirelessGrid;
private WirelessFluidGrid wirelessFluidGrid;
private Constructor constructor;
public ServerConfig() {
upgrades = new Upgrades();
@@ -50,6 +51,7 @@ public class ServerConfig {
storageMonitor = new StorageMonitor();
wirelessGrid = new WirelessGrid();
wirelessFluidGrid = new WirelessFluidGrid();
constructor = new Constructor();
spec = builder.build();
}
@@ -138,6 +140,10 @@ public class ServerConfig {
return wirelessFluidGrid;
}
public Constructor getConstructor() {
return constructor;
}
public ForgeConfigSpec getSpec() {
return spec;
}
@@ -675,4 +681,20 @@ public class ServerConfig {
return insertUsage.get();
}
}
public class Constructor {
private final ForgeConfigSpec.IntValue usage;
public Constructor() {
builder.push("constructor");
usage = builder.comment("The energy used by the Constructor").defineInRange("usage", 3, 0, Integer.MAX_VALUE);
builder.pop();
}
public int getUsage() {
return usage.get();
}
}
}

View File

@@ -3,13 +3,13 @@ package com.raoulvdberge.refinedstorage.container;
import com.raoulvdberge.refinedstorage.RSContainers;
import com.raoulvdberge.refinedstorage.container.slot.filter.FilterSlot;
import com.raoulvdberge.refinedstorage.container.slot.filter.FluidFilterSlot;
import com.raoulvdberge.refinedstorage.tile.TileConstructor;
import com.raoulvdberge.refinedstorage.tile.ConstructorTile;
import com.raoulvdberge.refinedstorage.tile.config.IType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.items.SlotItemHandler;
public class ConstructorContainer extends BaseContainer {
public ConstructorContainer(TileConstructor constructor, PlayerEntity player, int windowId) {
public ConstructorContainer(ConstructorTile constructor, PlayerEntity player, int windowId) {
super(RSContainers.CONSTRUCTOR, constructor, player, windowId);
for (int i = 0; i < 4; ++i) {

View File

@@ -1,18 +1,11 @@
package com.raoulvdberge.refinedstorage.container.slot.filter;
import com.raoulvdberge.refinedstorage.container.slot.BaseSlot;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SkullItem;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class FilterSlot extends BaseSlot {
public static final int FILTER_ALLOW_SIZE = 1;
@@ -34,8 +27,7 @@ public class FilterSlot extends BaseSlot {
public boolean isItemValid(@Nonnull ItemStack stack) {
if (super.isItemValid(stack)) {
if (isBlockAllowed()) {
// TODO!
return stack.getItem() instanceof BlockItem || /*stack.getItem() instanceof ItemBlockSpecial ||*/ stack.getItem() instanceof IPlantable || stack.getItem() instanceof SkullItem;
return stack.getItem() instanceof BlockItem;
}
return true;
@@ -60,25 +52,4 @@ public class FilterSlot extends BaseSlot {
public boolean isBlockAllowed() {
return (flags & FILTER_ALLOW_BLOCKS) == FILTER_ALLOW_BLOCKS;
}
@Nullable
public static BlockState getBlockState(World world, BlockPos pos, @Nullable ItemStack stack) {
if (stack != null) {
Item item = stack.getItem();
// TODO if (item instanceof ItemBlockSpecial) {
// return ((ItemBlockSpecial) item).getBlock().getDefaultState();
/*} else*/
/*if (item instanceof SkullItem) {
return Blocks.SKELETON_SKULL.getDefaultState();
} else */
if (item instanceof BlockItem) {
return (((BlockItem) item).getBlock()).getDefaultState();
} else if (item instanceof IPlantable) {
return ((IPlantable) item).getPlant(world, pos);
}
}
return null;
}
}

View File

@@ -1,13 +0,0 @@
package com.raoulvdberge.refinedstorage.render.constants;
import com.raoulvdberge.refinedstorage.render.collision.CollisionGroup;
import com.raoulvdberge.refinedstorage.util.CollisionUtils;
public final class ConstantsConstructor {
public static final CollisionGroup HEAD_NORTH = new CollisionGroup().addItem(CollisionUtils.getBounds(2, 2, 0, 14, 14, 2)).setCanAccessGui(true);
public static final CollisionGroup HEAD_EAST = new CollisionGroup().addItem(CollisionUtils.getBounds(14, 2, 2, 16, 14, 14)).setCanAccessGui(true);
public static final CollisionGroup HEAD_SOUTH = new CollisionGroup().addItem(CollisionUtils.getBounds(2, 2, 14, 14, 14, 16)).setCanAccessGui(true);
public static final CollisionGroup HEAD_WEST = new CollisionGroup().addItem(CollisionUtils.getBounds(0, 2, 2, 2, 14, 14)).setCanAccessGui(true);
public static final CollisionGroup HEAD_DOWN = new CollisionGroup().addItem(CollisionUtils.getBounds(2, 0, 2, 14, 2, 14)).setCanAccessGui(true);
public static final CollisionGroup HEAD_UP = new CollisionGroup().addItem(CollisionUtils.getBounds(2, 14, 2, 14, 16, 14)).setCanAccessGui(true);
}

View File

@@ -6,22 +6,23 @@ import com.raoulvdberge.refinedstorage.screen.widget.sidebutton.ConstructorDropS
import com.raoulvdberge.refinedstorage.screen.widget.sidebutton.ExactModeSideButton;
import com.raoulvdberge.refinedstorage.screen.widget.sidebutton.RedstoneModeSideButton;
import com.raoulvdberge.refinedstorage.screen.widget.sidebutton.TypeSideButton;
import com.raoulvdberge.refinedstorage.tile.TileConstructor;
import com.raoulvdberge.refinedstorage.tile.ConstructorTile;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
public class GuiConstructor extends BaseScreen<ConstructorContainer> {
public GuiConstructor(ConstructorContainer container, PlayerInventory inventory) {
super(container, 211, 137, inventory, null); // TODO TextComponent
public class ConstructorScreen extends BaseScreen<ConstructorContainer> {
public ConstructorScreen(ConstructorContainer container, PlayerInventory inventory, ITextComponent title) {
super(container, 211, 137, inventory, title);
}
@Override
public void onPostInit(int x, int y) {
addSideButton(new RedstoneModeSideButton(this, TileConstructor.REDSTONE_MODE));
addSideButton(new RedstoneModeSideButton(this, ConstructorTile.REDSTONE_MODE));
addSideButton(new TypeSideButton(this, TileConstructor.TYPE));
addSideButton(new TypeSideButton(this, ConstructorTile.TYPE));
addSideButton(new ExactModeSideButton(this, TileConstructor.COMPARE));
addSideButton(new ExactModeSideButton(this, ConstructorTile.COMPARE));
addSideButton(new ConstructorDropSideButton(this));
}
@@ -38,7 +39,7 @@ public class GuiConstructor extends BaseScreen<ConstructorContainer> {
@Override
public void renderForeground(int mouseX, int mouseY) {
renderString(7, 7, I18n.format("gui.refinedstorage:constructor"));
renderString(7, 7, title.getFormattedText());
renderString(7, 43, I18n.format("container.inventory"));
}
}

View File

@@ -1,7 +1,7 @@
package com.raoulvdberge.refinedstorage.screen.widget.sidebutton;
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
import com.raoulvdberge.refinedstorage.tile.TileConstructor;
import com.raoulvdberge.refinedstorage.tile.ConstructorTile;
import com.raoulvdberge.refinedstorage.tile.data.TileDataManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.TextFormatting;
@@ -13,16 +13,16 @@ public class ConstructorDropSideButton extends SideButton {
@Override
protected void renderButtonIcon(int x, int y) {
screen.blit(x, y, 64 + (TileConstructor.DROP.getValue() ? 16 : 0), 16, 16, 16);
screen.blit(x, y, 64 + (ConstructorTile.DROP.getValue() ? 16 : 0), 16, 16, 16);
}
@Override
public String getTooltip() {
return I18n.format("sidebutton.refinedstorage.constructor.drop") + "\n" + TextFormatting.GRAY + I18n.format(TileConstructor.DROP.getValue() ? "gui.yes" : "gui.no");
return I18n.format("sidebutton.refinedstorage.constructor.drop") + "\n" + TextFormatting.GRAY + I18n.format(ConstructorTile.DROP.getValue() ? "gui.yes" : "gui.no");
}
@Override
public void onPress() {
TileDataManager.setParameter(TileConstructor.DROP, !TileConstructor.DROP.getValue());
TileDataManager.setParameter(ConstructorTile.DROP, !ConstructorTile.DROP.getValue());
}
}

View File

@@ -1,7 +1,7 @@
package com.raoulvdberge.refinedstorage.tile;
import com.raoulvdberge.refinedstorage.RSTiles;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeConstructor;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.ConstructorNetworkNode;
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
import com.raoulvdberge.refinedstorage.tile.config.IType;
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
@@ -11,15 +11,15 @@ import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class TileConstructor extends NetworkNodeTile<NetworkNodeConstructor> {
public static final TileDataParameter<Integer, TileConstructor> COMPARE = IComparable.createParameter();
public static final TileDataParameter<Integer, TileConstructor> TYPE = IType.createParameter();
public static final TileDataParameter<Boolean, TileConstructor> DROP = new TileDataParameter<>(DataSerializers.BOOLEAN, false, t -> t.getNode().isDrop(), (t, v) -> {
public class ConstructorTile extends NetworkNodeTile<ConstructorNetworkNode> {
public static final TileDataParameter<Integer, ConstructorTile> COMPARE = IComparable.createParameter();
public static final TileDataParameter<Integer, ConstructorTile> TYPE = IType.createParameter();
public static final TileDataParameter<Boolean, ConstructorTile> DROP = new TileDataParameter<>(DataSerializers.BOOLEAN, false, t -> t.getNode().isDrop(), (t, v) -> {
t.getNode().setDrop(v);
t.getNode().markDirty();
});
public TileConstructor() {
public ConstructorTile() {
super(RSTiles.CONSTRUCTOR);
dataManager.addWatchedParameter(COMPARE);
@@ -29,7 +29,7 @@ public class TileConstructor extends NetworkNodeTile<NetworkNodeConstructor> {
@Override
@Nonnull
public NetworkNodeConstructor createNode(World world, BlockPos pos) {
return new NetworkNodeConstructor(world, pos);
public ConstructorNetworkNode createNode(World world, BlockPos pos) {
return new ConstructorNetworkNode(world, pos);
}
}

View File

@@ -1,98 +1,180 @@
{
"forge_marker": 1,
"defaults": {
"textures": {
"cable": "refinedstorage:blocks/cable",
"particle": "refinedstorage:blocks/cable",
"front": "refinedstorage:blocks/constructor/constructor",
"cutout": "refinedstorage:blocks/constructor/cutouts/disconnected",
"border": "refinedstorage:blocks/cable_part_border"
},
"model": "refinedstorage:cable_core",
"uvlock": true,
"transform": "forge:default-block"
},
"variants": {
"connected": {
"true": {
"textures": {
"cutout": "refinedstorage:blocks/constructor/cutouts/connected"
}
},
"false": {
"multipart": [
{
"apply": {
"model": "refinedstorage:block/cable_core"
}
},
"direction": {
"north": {
"submodel": "refinedstorage:constructor_destructor"
{
"when": {
"north": true
},
"east": {
"submodel": "refinedstorage:constructor_destructor",
"apply": {
"model": "refinedstorage:block/cable_extension"
}
},
{
"when": {
"east": true
},
"apply": {
"model": "refinedstorage:block/cable_extension",
"y": 90
}
},
{
"when": {
"south": true
},
"south": {
"submodel": "refinedstorage:constructor_destructor",
"apply": {
"model": "refinedstorage:block/cable_extension",
"x": 180
}
},
{
"when": {
"west": true
},
"west": {
"submodel": "refinedstorage:constructor_destructor",
"apply": {
"model": "refinedstorage:block/cable_extension",
"y": 270
}
},
{
"when": {
"up": true
},
"up": {
"submodel": "refinedstorage:constructor_destructor",
"apply": {
"model": "refinedstorage:block/cable_extension",
"x": 270
}
},
{
"when": {
"down": true
},
"down": {
"submodel": "refinedstorage:constructor_destructor",
"apply": {
"model": "refinedstorage:block/cable_extension",
"x": 90
}
},
"north": {
"true": {
"submodel": "refinedstorage:cable_extension"
{
"when": {
"direction": "north",
"connected": true
},
"false": {
"apply": {
"model": "refinedstorage:block/constructor_connected"
}
},
"east": {
"true": {
"submodel": "refinedstorage:cable_extension",
{
"when": {
"direction": "east",
"connected": true
},
"apply": {
"model": "refinedstorage:block/constructor_connected",
"y": 90
},
"false": {
}
},
"south": {
"true": {
"submodel": "refinedstorage:cable_extension",
{
"when": {
"direction": "south",
"connected": true
},
"apply": {
"model": "refinedstorage:block/constructor_connected",
"x": 180
},
"false": {
}
},
"west": {
"true": {
"submodel": "refinedstorage:cable_extension",
{
"when": {
"direction": "west",
"connected": true
},
"apply": {
"model": "refinedstorage:block/constructor_connected",
"y": 270
},
"false": {
}
},
"up": {
"true": {
"submodel": "refinedstorage:cable_extension",
{
"when": {
"direction": "up",
"connected": true
},
"apply": {
"model": "refinedstorage:block/constructor_connected",
"x": 270
},
"false": {
}
},
"down": {
"true": {
"submodel": "refinedstorage:cable_extension",
"x": 90
{
"when": {
"direction": "down",
"connected": true
},
"false": {
"apply": {
"model": "refinedstorage:block/constructor_connected",
"x": 90
}
},
{
"when": {
"direction": "north",
"connected": false
},
"apply": {
"model": "refinedstorage:block/constructor_disconnected"
}
},
{
"when": {
"direction": "east",
"connected": false
},
"apply": {
"model": "refinedstorage:block/constructor_disconnected",
"y": 90
}
},
{
"when": {
"direction": "south",
"connected": false
},
"apply": {
"model": "refinedstorage:block/constructor_disconnected",
"x": 180
}
},
{
"when": {
"direction": "west",
"connected": false
},
"apply": {
"model": "refinedstorage:block/constructor_disconnected",
"y": 270
}
},
{
"when": {
"direction": "up",
"connected": false
},
"apply": {
"model": "refinedstorage:block/constructor_disconnected",
"x": 270
}
},
{
"when": {
"direction": "down",
"connected": false
},
"apply": {
"model": "refinedstorage:block/constructor_disconnected",
"x": 90
}
}
}
]
}

View File

@@ -2,11 +2,8 @@
"forge_marker": 1,
"defaults": {
"textures": {
"cable": "refinedstorage:blocks/cable",
"particle": "refinedstorage:blocks/cable",
"front": "refinedstorage:blocks/destructor/destructor",
"cutout": "refinedstorage:blocks/destructor/cutouts/disconnected",
"border": "refinedstorage:blocks/cable_part_border"
"cutout": "refinedstorage:blocks/destructor/cutouts/disconnected"
},
"model": "refinedstorage:cable_core",
"uvlock": true,

View File

@@ -25,7 +25,7 @@
"gui.refinedstorage.exporter": "Exporter",
"gui.refinedstorage.detector": "Detector",
"gui.refinedstorage:destructor": "Destructor",
"gui.refinedstorage:constructor": "Constructor",
"gui.refinedstorage.constructor": "Constructor",
"gui.refinedstorage.relay": "Relay",
"gui.refinedstorage.interface.import": "Interface Import",
"gui.refinedstorage.interface.export": "Interface Export",
@@ -191,7 +191,7 @@
"block.refinedstorage.detector": "Detector",
"block.refinedstorage.machine_casing": "Machine Casing",
"block.refinedstorage:destructor": "Destructor",
"block.refinedstorage:constructor": "Constructor",
"block.refinedstorage.constructor": "Constructor",
"block.refinedstorage.1k_storage_block": "1k Storage Block",
"block.refinedstorage.4k_storage_block": "4k Storage Block",
"block.refinedstorage.16k_storage_block": "16k Storage Block",

View File

@@ -0,0 +1,7 @@
{
"parent": "refinedstorage:block/constructor_destructor",
"textures": {
"front": "refinedstorage:block/constructor/constructor",
"cutout": "refinedstorage:block/constructor/cutouts/connected"
}
}

View File

@@ -1,5 +1,7 @@
{
"__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)",
"textures": {
"border": "refinedstorage:block/cable_part_border"
},
"elements": [
{
"name": "Line1",

View File

@@ -0,0 +1,7 @@
{
"parent": "refinedstorage:block/constructor_destructor",
"textures": {
"front": "refinedstorage:block/constructor/constructor",
"cutout": "refinedstorage:block/constructor/cutouts/disconnected"
}
}

View File

@@ -0,0 +1,389 @@
{
"parent": "block/block",
"textures": {
"cable": "refinedstorage:block/cable",
"front": "refinedstorage:block/constructor/constructor",
"cutout": "refinedstorage:block/constructor/cutouts/disconnected",
"border": "refinedstorage:block/cable_part_border"
},
"elements": [
{
"name": "Core",
"from": [
6,
6,
6
],
"to": [
10,
10,
10
],
"faces": {
"north": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"east": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"south": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"west": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"up": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"down": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
}
}
},
{
"name": "Part1",
"from": [
10,
6,
6
],
"to": [
16,
10,
10
],
"rotation": {
"angle": 0,
"axis": "y",
"origin": [
16,
8,
9
]
},
"faces": {
"north": {
"uv": [
0,
6,
6,
10
],
"texture": "#cable"
},
"east": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"south": {
"uv": [
10,
6,
16,
10
],
"texture": "#cable"
},
"west": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"up": {
"uv": [
10,
6,
16,
10
],
"texture": "#cable"
},
"down": {
"uv": [
10,
6,
16,
10
],
"texture": "#cable"
}
}
},
{
"name": "Part2",
"from": [
0,
6,
6
],
"to": [
6,
10,
10
],
"rotation": {
"angle": 0,
"axis": "y",
"origin": [
6,
8,
9
]
},
"faces": {
"north": {
"uv": [
10,
6,
16,
10
],
"texture": "#cable"
},
"east": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"south": {
"uv": [
0,
6,
6,
10
],
"texture": "#cable"
},
"west": {
"uv": [
6,
6,
10,
10
],
"texture": "#cable"
},
"up": {
"uv": [
0,
6,
6,
10
],
"texture": "#cable"
},
"down": {
"uv": [
0,
6,
6,
10
],
"texture": "#cable"
}
}
},
{
"name": "Line1",
"from": [
7.0,
7.0,
2.0
],
"to": [
9.0,
9.0,
6.0
],
"faces": {
"east": {
"texture": "#border",
"uv": [
0.0,
0.0,
4.0,
2.0
]
},
"south": {
"texture": "#border",
"uv": [
0.0,
0.0,
4.0,
4.0
]
},
"west": {
"texture": "#border",
"uv": [
0.0,
0.0,
4.0,
2.0
]
},
"up": {
"texture": "#border",
"uv": [
0.0,
0.0,
2.0,
4.0
]
},
"down": {
"texture": "#border",
"uv": [
0.0,
0.0,
2.0,
4.0
]
}
}
},
{
"name": "Line2",
"from": [
2.0,
2.0,
0.0
],
"to": [
14.0,
14.0,
2.0
],
"faces": {
"north": {
"texture": "#front",
"uv": [
0.0,
0.0,
16.0,
16.0
]
},
"east": {
"texture": "#border",
"uv": [
14.0,
0.0,
16.0,
16.0
]
},
"south": {
"texture": "#border",
"uv": [
0.0,
0.0,
16.0,
16.0
]
},
"west": {
"texture": "#border",
"uv": [
0.0,
0.0,
2.0,
16.0
]
},
"up": {
"texture": "#border",
"uv": [
2.0,
0.0,
14.0,
2.0
]
},
"down": {
"texture": "#border",
"uv": [
2.0,
14.0,
14.0,
16.0
]
}
}
},
{
"name": "Line3",
"from": [
2.0,
2.0,
0.0
],
"to": [
14.0,
14.0,
2.0
],
"faces": {
"north": {
"texture": "#cutout",
"uv": [
0.0,
0.0,
16.0,
16.0
]
}
}
}
]
}

View File

@@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "refinedstorage:constructor"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View File

@@ -10,7 +10,7 @@
"item": "refinedstorage:quartz_enriched_iron"
},
"C": {
"item": "#construction_core"
"item": "refinedstorage:construction_core"
},
"R": {
"item": "minecraft:redstone"
@@ -19,7 +19,7 @@
"item": "refinedstorage:cable"
},
"I": {
"item": "#improved_processor"
"item": "refinedstorage:improved_processor"
}
},
"result": {