As though they never existed
- Banished high logistics from this branch to resolve build issues
This commit is contained in:
parent
8259a0c275
commit
a821172061
53 changed files with 4 additions and 4976 deletions
|
@ -190,13 +190,6 @@ public enum AllBlocks {
|
||||||
PULSE_REPEATER(new PulseRepeaterBlock()),
|
PULSE_REPEATER(new PulseRepeaterBlock()),
|
||||||
FLEXPEATER(new FlexpeaterBlock()),
|
FLEXPEATER(new FlexpeaterBlock()),
|
||||||
FLEXPEATER_INDICATOR(new RenderUtilityBlock()),
|
FLEXPEATER_INDICATOR(new RenderUtilityBlock()),
|
||||||
// LOGISTICAL_CASING(new NewLogisticalCasingBlock()),
|
|
||||||
// LOGISTICAL_CONTROLLER(new LogisticalControllerBlock()),
|
|
||||||
// LOGISTICAL_CONTROLLER_INDICATOR(new LogisticalControllerIndicatorBlock()),
|
|
||||||
// LOGISTICAL_INDEX(new LogisticalIndexBlock()),
|
|
||||||
// PACKAGE_FUNNEL(new PackageFunnelBlock()),
|
|
||||||
// LOGISTICIANS_TABLE(new LogisticiansTableBlock()),
|
|
||||||
// LOGISTICIANS_TABLE_INDICATOR(new RenderUtilityBlock()),
|
|
||||||
|
|
||||||
__CURIOSITIES__(),
|
__CURIOSITIES__(),
|
||||||
SYMMETRY_PLANE(new PlaneSymmetryBlock()),
|
SYMMETRY_PLANE(new PlaneSymmetryBlock()),
|
||||||
|
|
|
@ -30,9 +30,6 @@ public enum AllContainers {
|
||||||
SCHEMATIC_TABLE(SchematicTableContainer::new),
|
SCHEMATIC_TABLE(SchematicTableContainer::new),
|
||||||
SCHEMATICANNON(SchematicannonContainer::new),
|
SCHEMATICANNON(SchematicannonContainer::new),
|
||||||
FLEXCRATE(FlexcrateContainer::new),
|
FLEXCRATE(FlexcrateContainer::new),
|
||||||
// LOGISTICAL_INDEX(LogisticalIndexContainer::new),
|
|
||||||
// LOGISTICAL_CONTROLLER(LogisticalInventoryControllerContainer::new),
|
|
||||||
|
|
||||||
FILTER(FilterContainer::new),
|
FILTER(FilterContainer::new),
|
||||||
ATTRIBUTE_FILTER(AttributeFilterContainer::new),
|
ATTRIBUTE_FILTER(AttributeFilterContainer::new),
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||||
|
|
||||||
public enum AllEntities {
|
public enum AllEntities {
|
||||||
|
|
||||||
// CARDBOARD_BOX(CardboardBoxEntity::new, 30, 3, CardboardBoxEntity::build),
|
|
||||||
CONTRAPTION(ContraptionEntity::new, 30, 3, ContraptionEntity::build),
|
CONTRAPTION(ContraptionEntity::new, 30, 3, ContraptionEntity::build),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
|
@ -94,20 +94,8 @@ public enum AllItems {
|
||||||
GOGGLES(new GogglesItem(standardItemProperties()), true),
|
GOGGLES(new GogglesItem(standardItemProperties()), true),
|
||||||
|
|
||||||
__LOGISTICS__(),
|
__LOGISTICS__(),
|
||||||
// CARDBOARD_BOX(new CardboardBoxItem(standardItemProperties())),
|
|
||||||
// CARDBOARD_BOX_1(new CardboardBoxItem(standardItemProperties())),
|
|
||||||
// CARDBOARD_BOX_2(new CardboardBoxItem(standardItemProperties())),
|
|
||||||
// CARDBOARD_BOX_3(new CardboardBoxItem(standardItemProperties())),
|
|
||||||
|
|
||||||
FILTER(new FilterItem(standardItemProperties()), true),
|
FILTER(new FilterItem(standardItemProperties()), true),
|
||||||
PROPERTY_FILTER(new FilterItem(standardItemProperties()), true),
|
PROPERTY_FILTER(new FilterItem(standardItemProperties()), true),
|
||||||
// LOGISTICAL_FILTER(new FilterItem(standardItemProperties())),
|
|
||||||
// LOGISTICAL_DIAL(new LogisticalDialItem(standardItemProperties())),
|
|
||||||
// LOGISTICAL_CONTROLLER_SUPPLY(new LogisticalControllerItem(standardItemProperties(), Type.SUPPLY)),
|
|
||||||
// LOGISTICAL_CONTROLLER_REQUEST(new LogisticalControllerItem(standardItemProperties(), Type.REQUEST)),
|
|
||||||
// LOGISTICAL_CONTROLLER_STORAGE(new LogisticalControllerItem(standardItemProperties(), Type.STORAGE)),
|
|
||||||
// LOGISTICAL_CONTROLLER_CALCULATION(new LogisticalControllerItem(standardItemProperties(), Type.CALCULATION)),
|
|
||||||
// LOGISTICAL_CONTROLLER_TRANSACTIONS(new LogisticalControllerItem(standardItemProperties(), Type.TRANSACTIONS)),
|
|
||||||
|
|
||||||
__CURIOSITIES__(),
|
__CURIOSITIES__(),
|
||||||
PLACEMENT_HANDGUN(
|
PLACEMENT_HANDGUN(
|
||||||
|
|
|
@ -36,19 +36,15 @@ public enum AllPackets {
|
||||||
CONFIGURE_CHASSIS(ConfigureChassisPacket.class, ConfigureChassisPacket::new),
|
CONFIGURE_CHASSIS(ConfigureChassisPacket.class, ConfigureChassisPacket::new),
|
||||||
CONFIGURE_MOTOR(ConfigureMotorPacket.class, ConfigureMotorPacket::new),
|
CONFIGURE_MOTOR(ConfigureMotorPacket.class, ConfigureMotorPacket::new),
|
||||||
CONFIGURE_FLEXPEATER(ConfigureFlexpeaterPacket.class, ConfigureFlexpeaterPacket::new),
|
CONFIGURE_FLEXPEATER(ConfigureFlexpeaterPacket.class, ConfigureFlexpeaterPacket::new),
|
||||||
// CONFIGURE_LOGISTICAL_CONTROLLER(LogisticalControllerConfigurationPacket.class,
|
|
||||||
// LogisticalControllerConfigurationPacket::new),
|
|
||||||
CONFIGURE_MIXER(ConfigureMixerPacket.class, ConfigureMixerPacket::new),
|
CONFIGURE_MIXER(ConfigureMixerPacket.class, ConfigureMixerPacket::new),
|
||||||
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new),
|
PLACE_SCHEMATIC(SchematicPlacePacket.class, SchematicPlacePacket::new),
|
||||||
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new),
|
UPLOAD_SCHEMATIC(SchematicUploadPacket.class, SchematicUploadPacket::new),
|
||||||
// INDEX_ORDER_REQUEST(IndexOrderRequest.class, IndexOrderRequest::new),
|
|
||||||
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new),
|
CONFIGURE_FILTER(FilterScreenPacket.class, FilterScreenPacket::new),
|
||||||
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new),
|
CONFIGURE_FILTERING_AMOUNT(FilteringCountUpdatePacket.class, FilteringCountUpdatePacket::new),
|
||||||
|
|
||||||
// Server to Client
|
// Server to Client
|
||||||
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new),
|
SYMMETRY_EFFECT(SymmetryEffectPacket.class, SymmetryEffectPacket::new),
|
||||||
BEAM_EFFECT(BlockzapperBeamPacket.class, BlockzapperBeamPacket::new),
|
BEAM_EFFECT(BlockzapperBeamPacket.class, BlockzapperBeamPacket::new),
|
||||||
// INDEX_CONTAINER_UPDATE(IndexContainerUpdatePacket.class, IndexContainerUpdatePacket::new),
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -129,15 +129,6 @@ public enum AllTileEntities {
|
||||||
BELT_FUNNEL(FunnelTileEntity::new, AllBlocks.BELT_FUNNEL, AllBlocks.VERTICAL_FUNNEL),
|
BELT_FUNNEL(FunnelTileEntity::new, AllBlocks.BELT_FUNNEL, AllBlocks.VERTICAL_FUNNEL),
|
||||||
ENTITY_DETECTOR(BeltObserverTileEntity::new, AllBlocks.ENTITY_DETECTOR),
|
ENTITY_DETECTOR(BeltObserverTileEntity::new, AllBlocks.ENTITY_DETECTOR),
|
||||||
FLEXPEATER(FlexpeaterTileEntity::new, AllBlocks.FLEXPEATER),
|
FLEXPEATER(FlexpeaterTileEntity::new, AllBlocks.FLEXPEATER),
|
||||||
// LOGISTICAL_CASING(LogisticalCasingTileEntity::new, AllBlocks.LOGISTICAL_CASING),
|
|
||||||
// LOGISTICAL_SUPPLY_CONTROLLER(SupplyTileEntity::new, AllBlocks.LOGISTICAL_CONTROLLER),
|
|
||||||
// LOGISTICAL_REQUEST_CONTROLLER(RequestTileEntity::new, AllBlocks.LOGISTICAL_CONTROLLER),
|
|
||||||
// LOGISTICAL_STORAGE_CONTROLLER(StorageTileEntity::new, AllBlocks.LOGISTICAL_CONTROLLER),
|
|
||||||
// LOGISTICAL_CALCULATION_CONTROLLER(CalculationTileEntity::new, AllBlocks.LOGISTICAL_CONTROLLER),
|
|
||||||
// LOGISTICAL_TRANSATIONS_CONTROLLER(TransactionsTileEntity::new, AllBlocks.LOGISTICAL_CONTROLLER),
|
|
||||||
// LOGISTICAL_INDEX(LogisticalIndexTileEntity::new, AllBlocks.LOGISTICAL_INDEX),
|
|
||||||
// LOGISTICIANS_TABLE(LogisticiansTableTileEntity::new, AllBlocks.LOGISTICIANS_TABLE),
|
|
||||||
// PACKAGE_FUNNEL(PackageFunnelTileEntity::new, AllBlocks.PACKAGE_FUNNEL),
|
|
||||||
|
|
||||||
// Curiosities
|
// Curiosities
|
||||||
WINDOW_IN_A_BLOCK(WindowInABlockTileEntity::new, AllBlocks.WINDOW_IN_A_BLOCK),
|
WINDOW_IN_A_BLOCK(WindowInABlockTileEntity::new, AllBlocks.WINDOW_IN_A_BLOCK),
|
||||||
|
|
|
@ -13,17 +13,14 @@ import com.simibubi.create.modules.schematics.ServerSchematicLoader;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.merchant.villager.VillagerProfession;
|
|
||||||
import net.minecraft.inventory.container.ContainerType;
|
import net.minecraft.inventory.container.ContainerType;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||||
import net.minecraft.particles.ParticleType;
|
import net.minecraft.particles.ParticleType;
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
import net.minecraft.tileentity.TileEntityType;
|
||||||
import net.minecraft.village.PointOfInterestType;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
@ -45,8 +42,6 @@ public class Create {
|
||||||
public static RedstoneLinkNetworkHandler redstoneLinkNetworkHandler;
|
public static RedstoneLinkNetworkHandler redstoneLinkNetworkHandler;
|
||||||
public static TorquePropagator torquePropagator;
|
public static TorquePropagator torquePropagator;
|
||||||
public static ServerLagger lagger;
|
public static ServerLagger lagger;
|
||||||
// public static LogisticalNetworkHandler logisticalNetworkHandler;
|
|
||||||
// public static LogisticianHandler logisticianHandler;
|
|
||||||
|
|
||||||
public static ModConfig config;
|
public static ModConfig config;
|
||||||
|
|
||||||
|
@ -61,8 +56,6 @@ public class Create {
|
||||||
modEventBus.addGenericListener(IRecipeSerializer.class, AllRecipes::register);
|
modEventBus.addGenericListener(IRecipeSerializer.class, AllRecipes::register);
|
||||||
modEventBus.addGenericListener(TileEntityType.class, AllTileEntities::register);
|
modEventBus.addGenericListener(TileEntityType.class, AllTileEntities::register);
|
||||||
modEventBus.addGenericListener(ContainerType.class, AllContainers::register);
|
modEventBus.addGenericListener(ContainerType.class, AllContainers::register);
|
||||||
modEventBus.addGenericListener(VillagerProfession.class, Create::registerVillagerProfessions);
|
|
||||||
modEventBus.addGenericListener(PointOfInterestType.class, Create::registerPointsOfInterest);
|
|
||||||
modEventBus.addGenericListener(EntityType.class, AllEntities::register);
|
modEventBus.addGenericListener(EntityType.class, AllEntities::register);
|
||||||
modEventBus.addGenericListener(ParticleType.class, AllParticles::register);
|
modEventBus.addGenericListener(ParticleType.class, AllParticles::register);
|
||||||
|
|
||||||
|
@ -77,7 +70,6 @@ public class Create {
|
||||||
public static void init(final FMLCommonSetupEvent event) {
|
public static void init(final FMLCommonSetupEvent event) {
|
||||||
schematicReceiver = new ServerSchematicLoader();
|
schematicReceiver = new ServerSchematicLoader();
|
||||||
redstoneLinkNetworkHandler = new RedstoneLinkNetworkHandler();
|
redstoneLinkNetworkHandler = new RedstoneLinkNetworkHandler();
|
||||||
// logisticalNetworkHandler = new LogisticalNetworkHandler();
|
|
||||||
torquePropagator = new TorquePropagator();
|
torquePropagator = new TorquePropagator();
|
||||||
lagger = new ServerLagger();
|
lagger = new ServerLagger();
|
||||||
|
|
||||||
|
@ -89,14 +81,6 @@ public class Create {
|
||||||
new CreateCommand(event.getCommandDispatcher());
|
new CreateCommand(event.getCommandDispatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerVillagerProfessions(RegistryEvent.Register<VillagerProfession> event) {
|
|
||||||
// LogisticianHandler.registerVillagerProfessions(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerPointsOfInterest(RegistryEvent.Register<PointOfInterestType> event) {
|
|
||||||
// LogisticianHandler.registerPointsOfInterest(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void createConfigs(ModConfig.ModConfigEvent event) {
|
public static void createConfigs(ModConfig.ModConfigEvent event) {
|
||||||
if (event.getConfig().getSpec() == CreateConfig.specification)
|
if (event.getConfig().getSpec() == CreateConfig.specification)
|
||||||
config = event.getConfig();
|
config = event.getConfig();
|
||||||
|
|
|
@ -5,14 +5,15 @@ import java.util.function.Supplier;
|
||||||
import com.simibubi.create.AllItems;
|
import com.simibubi.create.AllItems;
|
||||||
|
|
||||||
import net.minecraft.item.IItemTier;
|
import net.minecraft.item.IItemTier;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.item.crafting.Ingredient;
|
import net.minecraft.item.crafting.Ingredient;
|
||||||
import net.minecraft.util.LazyLoadBase;
|
import net.minecraft.util.LazyLoadBase;
|
||||||
|
|
||||||
public enum AllToolTiers implements IItemTier {
|
public enum AllToolTiers implements IItemTier {
|
||||||
|
|
||||||
// BLAZING(3, 750, 10.0F, 2.5F, 16, () -> {
|
BLAZING(3, 750, 10.0F, 2.5F, 16, () -> {
|
||||||
// return Ingredient.fromItems(AllItems.BLAZE_BRASS_CUBE.item);
|
return Ingredient.fromItems(Items.BLAZE_ROD);
|
||||||
// }),
|
}),
|
||||||
|
|
||||||
ROSE_QUARTZ(3, 1644, 7.0F, 2.0F, 24, () -> {
|
ROSE_QUARTZ(3, 1644, 7.0F, 2.0F, 24, () -> {
|
||||||
return Ingredient.fromItems(AllItems.POLISHED_ROSE_QUARTZ.item);
|
return Ingredient.fromItems(AllItems.POLISHED_ROSE_QUARTZ.item);
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.item.IAddedByOther;
|
|
||||||
import com.simibubi.create.foundation.item.IItemWithColorHandler;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.color.IItemColor;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.ItemUseContext;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.ActionResult;
|
|
||||||
import net.minecraft.util.ActionResultType;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class LogisticalDialItem extends Item implements IItemWithColorHandler, IAddedByOther {
|
|
||||||
|
|
||||||
public LogisticalDialItem(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IItemColor getColorHandler() {
|
|
||||||
return (stack, layer) -> {
|
|
||||||
if (layer == 1 && stack.getOrCreateTag().contains("NetworkIDLeast"))
|
|
||||||
return LogisticalActorTileEntity.colorFromUUID(stack.getTag().getUniqueId("NetworkID"));
|
|
||||||
return 0xFFFFFF;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
|
||||||
if (worldIn.isRemote && !stack.hasTag())
|
|
||||||
stack.getOrCreateTag().putUniqueId("NetworkID", UUID.randomUUID());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResultType onItemUse(ItemUseContext context) {
|
|
||||||
ItemStack heldItem = context.getItem();
|
|
||||||
boolean isRemote = context.getWorld().isRemote;
|
|
||||||
|
|
||||||
if (!context.getPlayer().isAllowEdit())
|
|
||||||
return super.onItemUse(context);
|
|
||||||
|
|
||||||
TileEntity te = context.getWorld().getTileEntity(context.getPos());
|
|
||||||
if (!(te instanceof LogisticalActorTileEntity)) {
|
|
||||||
if (context.isPlacerSneaking()) {
|
|
||||||
if (!isRemote)
|
|
||||||
heldItem.getTag().putUniqueId("NetworkID", UUID.randomUUID());
|
|
||||||
context.getPlayer().getCooldownTracker().setCooldown(heldItem.getItem(), 5);
|
|
||||||
return ActionResultType.SUCCESS;
|
|
||||||
}
|
|
||||||
return super.onItemUse(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
LogisticalActorTileEntity tileEntity = (LogisticalActorTileEntity) te;
|
|
||||||
if (context.isPlacerSneaking()) {
|
|
||||||
if (!isRemote)
|
|
||||||
heldItem.getTag().putUniqueId("NetworkID", tileEntity.getNetworkId());
|
|
||||||
context.getPlayer().getCooldownTracker().setCooldown(heldItem.getItem(), 5);
|
|
||||||
return ActionResultType.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
tileEntity.setNetworkId(heldItem.getTag().getUniqueId("NetworkID"));
|
|
||||||
return ActionResultType.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
|
|
||||||
if (!playerIn.isSneaking())
|
|
||||||
return super.onItemRightClick(worldIn, playerIn, handIn);
|
|
||||||
|
|
||||||
ItemStack heldItem = playerIn.getHeldItem(handIn);
|
|
||||||
if (!worldIn.isRemote) {
|
|
||||||
heldItem.getTag().putUniqueId("NetworkID", UUID.randomUUID());
|
|
||||||
playerIn.inventory.markDirty();
|
|
||||||
}
|
|
||||||
playerIn.getCooldownTracker().setCooldown(heldItem.getItem(), 5);
|
|
||||||
return new ActionResult<>(ActionResultType.SUCCESS, heldItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,154 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.PriorityQueue;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalTask;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.DepositTask;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.SupplyTask;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.StorageTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.TransactionsTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.index.LogisticalIndexTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.villager.PackageFunnelTileEntity;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
|
|
||||||
public class LogisticalNetwork {
|
|
||||||
|
|
||||||
public List<TransactionsTileEntity> taskQueues = new ArrayList<>();
|
|
||||||
public List<LogisticalIndexTileEntity> indexers = new ArrayList<>();
|
|
||||||
public Set<PackageFunnelTileEntity> packageTargets = new HashSet<>();
|
|
||||||
public PriorityQueue<LogisticalTask> internalTaskQueue = new PriorityQueue<>();
|
|
||||||
public PriorityQueue<LogisticalActorTileEntity> suppliers = new PriorityQueue<>();
|
|
||||||
public PriorityQueue<LogisticalActorTileEntity> receivers = new PriorityQueue<>();
|
|
||||||
public int participants = 0;
|
|
||||||
public boolean tasksUpdated;
|
|
||||||
|
|
||||||
public void addController(LogisticalActorTileEntity te) {
|
|
||||||
if (te instanceof TransactionsTileEntity) {
|
|
||||||
if (taskQueues.contains(te))
|
|
||||||
return;
|
|
||||||
taskQueues.add((TransactionsTileEntity) te);
|
|
||||||
}
|
|
||||||
if (te instanceof LogisticalIndexTileEntity) {
|
|
||||||
if (indexers.contains(te))
|
|
||||||
return;
|
|
||||||
indexers.add((LogisticalIndexTileEntity) te);
|
|
||||||
}
|
|
||||||
if (te.isSupplier()) {
|
|
||||||
if (suppliers.contains(te))
|
|
||||||
return;
|
|
||||||
suppliers.add(te);
|
|
||||||
}
|
|
||||||
if (te.isReceiver()) {
|
|
||||||
if (receivers.contains(te))
|
|
||||||
return;
|
|
||||||
receivers.add(te);
|
|
||||||
reAdvertiseReceivers();
|
|
||||||
}
|
|
||||||
participants++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPackageTarget(PackageFunnelTileEntity te) {
|
|
||||||
packageTargets.add(te);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removePackageTarget(PackageFunnelTileEntity te) {
|
|
||||||
packageTargets.remove(te);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reAdvertiseReceivers() {
|
|
||||||
indexers.forEach(LogisticalIndexTileEntity::syncReceivers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeController(LogisticalActorTileEntity te) {
|
|
||||||
if (te instanceof TransactionsTileEntity)
|
|
||||||
if (!taskQueues.remove((TransactionsTileEntity) te))
|
|
||||||
return;
|
|
||||||
if (te instanceof LogisticalIndexTileEntity)
|
|
||||||
if (!indexers.remove((LogisticalIndexTileEntity) te))
|
|
||||||
return;
|
|
||||||
if (te.isSupplier())
|
|
||||||
if (!suppliers.remove(te))
|
|
||||||
return;
|
|
||||||
if (te.isReceiver()) {
|
|
||||||
if (!receivers.remove(te))
|
|
||||||
return;
|
|
||||||
reAdvertiseReceivers();
|
|
||||||
}
|
|
||||||
participants--;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return participants == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enqueueTask(LogisticalTask task) {
|
|
||||||
internalTaskQueue.add(task);
|
|
||||||
|
|
||||||
Minecraft.getInstance().player.sendMessage(new StringTextComponent(internalTaskQueue.toString()));
|
|
||||||
|
|
||||||
if (task instanceof SupplyTask)
|
|
||||||
suppliers.forEach(LogisticalActorTileEntity::notifyTaskUpdate);
|
|
||||||
if (task instanceof DepositTask)
|
|
||||||
receivers.forEach(LogisticalActorTileEntity::notifyTaskUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNextAvailableAddress(LogisticalActorTileEntity te) {
|
|
||||||
Predicate<String> isTaken = s -> false;
|
|
||||||
String prefix = "";
|
|
||||||
|
|
||||||
if (te instanceof TransactionsTileEntity) {
|
|
||||||
prefix = "Task Manager";
|
|
||||||
isTaken = s -> isNameTaken(taskQueues, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (te instanceof LogisticalIndexTileEntity) {
|
|
||||||
prefix = "Index";
|
|
||||||
isTaken = s -> isNameTaken(indexers, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (te instanceof StorageTileEntity) {
|
|
||||||
prefix = "Storage";
|
|
||||||
isTaken = s -> isNameTaken(suppliers, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (te.isSupplier()) {
|
|
||||||
prefix = "Supply";
|
|
||||||
isTaken = s -> isNameTaken(suppliers, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (te.isReceiver()) {
|
|
||||||
prefix = "Request";
|
|
||||||
isTaken = s -> isNameTaken(receivers, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
String name;
|
|
||||||
do {
|
|
||||||
name = prefix + (i == 0 ? "" : " " + i);
|
|
||||||
i++;
|
|
||||||
} while (isTaken.test(name));
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T extends LogisticalActorTileEntity> boolean isNameTaken(Collection<T> list, String name) {
|
|
||||||
for (T controller : list)
|
|
||||||
if (controller.address.equals(name))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matchAddresses(String addr1, String addr2) {
|
|
||||||
return addr1.toLowerCase().equals(addr2.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.simibubi.create.Create;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity;
|
|
||||||
|
|
||||||
import net.minecraft.world.IWorld;
|
|
||||||
|
|
||||||
public class LogisticalNetworkHandler {
|
|
||||||
|
|
||||||
static Map<IWorld, Map<UUID, LogisticalNetwork>> networks = new HashMap<>();
|
|
||||||
|
|
||||||
public void onLoadWorld(IWorld world) {
|
|
||||||
networks.put(world, new HashMap<>());
|
|
||||||
Create.logger.debug("Prepared Logistical Network Map for " + world.getDimension().getType().getRegistryName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnloadWorld(IWorld world) {
|
|
||||||
networks.remove(world);
|
|
||||||
Create.logger.debug("Removed Logistical Network Map for " + world.getDimension().getType().getRegistryName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogisticalNetwork handleAdded(LogisticalActorTileEntity te) {
|
|
||||||
LogisticalNetwork networkByID = getNetworkByID(te.getWorld(), te.getNetworkId());
|
|
||||||
if (te.address == null || te.address.isEmpty()) {
|
|
||||||
te.address = networkByID.getNextAvailableAddress(te);
|
|
||||||
te.sendData();
|
|
||||||
}
|
|
||||||
networkByID.addController(te);
|
|
||||||
return networkByID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleRemoved(LogisticalActorTileEntity te) {
|
|
||||||
getNetworkByID(te.getWorld(), te.getNetworkId()).removeController(te);
|
|
||||||
removeIfEmpty(te.getWorld(), te.getNetworkId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogisticalNetwork getNetworkByID(IWorld world, UUID id) {
|
|
||||||
Map<UUID, LogisticalNetwork> worldNets = networks.get(world);
|
|
||||||
if (!worldNets.containsKey(id))
|
|
||||||
worldNets.put(id, new LogisticalNetwork());
|
|
||||||
return worldNets.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeIfEmpty(IWorld world, UUID id) {
|
|
||||||
Map<UUID, LogisticalNetwork> worldNets = networks.get(world);
|
|
||||||
if (worldNets.get(id).isEmpty())
|
|
||||||
worldNets.remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.IWorld;
|
|
||||||
|
|
||||||
public interface ILogisticalCasingAttachment {
|
|
||||||
|
|
||||||
public void onCasingUpdated(IWorld world, BlockPos pos, @Nullable LogisticalCasingTileEntity te);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public class IncrementalInventoryUpdate {
|
|
||||||
|
|
||||||
public ItemStack item;
|
|
||||||
public int newAmount;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,143 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.simibubi.create.Create;
|
|
||||||
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
|
||||||
import com.simibubi.create.foundation.utility.ColorHelper;
|
|
||||||
import com.simibubi.create.modules.logistics.management.LogisticalNetwork;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.tileentity.ITickableTileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
|
|
||||||
public abstract class LogisticalActorTileEntity extends SyncedTileEntity
|
|
||||||
implements Comparable<LogisticalActorTileEntity>, ITickableTileEntity {
|
|
||||||
|
|
||||||
public static final int COOLDOWN = 20;
|
|
||||||
|
|
||||||
public Priority priority = Priority.LOW;
|
|
||||||
public String address = "";
|
|
||||||
|
|
||||||
protected LogisticalNetwork network;
|
|
||||||
protected UUID networkId;
|
|
||||||
protected boolean initialize;
|
|
||||||
protected boolean checkTasks;
|
|
||||||
protected int taskCooldown;
|
|
||||||
|
|
||||||
public LogisticalActorTileEntity(TileEntityType<?> tileEntityTypeIn) {
|
|
||||||
super(tileEntityTypeIn);
|
|
||||||
initialize = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
if (initialize) {
|
|
||||||
initialize = false;
|
|
||||||
initialize();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taskCooldown > 0)
|
|
||||||
taskCooldown--;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initialize() {
|
|
||||||
if (networkId != null)
|
|
||||||
handleAdded();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
if (networkId != null)
|
|
||||||
handleRemoved();
|
|
||||||
super.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notifyTaskUpdate() {
|
|
||||||
checkTasks = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundNBT write(CompoundNBT compound) {
|
|
||||||
if (networkId != null)
|
|
||||||
compound.putUniqueId("NetworkID", networkId);
|
|
||||||
compound.putString("Address", address);
|
|
||||||
compound.putInt("Priority", priority.ordinal());
|
|
||||||
return super.write(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getNetworkId() {
|
|
||||||
return networkId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(CompoundNBT compound) {
|
|
||||||
if (compound.contains("NetworkIDLeast"))
|
|
||||||
networkId = compound.getUniqueId("NetworkID");
|
|
||||||
address = compound.getString("Address");
|
|
||||||
priority = Priority.values()[compound.getInt("Priority")];
|
|
||||||
super.read(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColor() {
|
|
||||||
return colorFromUUID(networkId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> LazyOptional<T> getCasingCapability(Capability<T> cap, Direction side) {
|
|
||||||
return LazyOptional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNetworkId(UUID uniqueId) {
|
|
||||||
if (getNetwork() != null)
|
|
||||||
handleRemoved();
|
|
||||||
networkId = uniqueId;
|
|
||||||
handleAdded();
|
|
||||||
markDirty();
|
|
||||||
sendData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleAdded() {
|
|
||||||
if (world.isRemote)
|
|
||||||
return;
|
|
||||||
if (getNetwork() != null)
|
|
||||||
return;
|
|
||||||
network = Create.logisticalNetworkHandler.handleAdded(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleRemoved() {
|
|
||||||
if (world.isRemote)
|
|
||||||
return;
|
|
||||||
Create.logisticalNetworkHandler.handleRemoved(this);
|
|
||||||
network = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSupplier() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isReceiver() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(LogisticalActorTileEntity o) {
|
|
||||||
return this.priority.compareTo(o.priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogisticalNetwork getNetwork() {
|
|
||||||
return network;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Priority getPriority() {
|
|
||||||
return priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum Priority {
|
|
||||||
HIGHEST, HIGH, LOWEST, LOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,271 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import static net.minecraft.util.Direction.AxisDirection.POSITIVE;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
|
||||||
import com.simibubi.create.foundation.utility.VoxelShaper;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
|
||||||
import net.minecraft.state.BooleanProperty;
|
|
||||||
import net.minecraft.state.EnumProperty;
|
|
||||||
import net.minecraft.state.IProperty;
|
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.Direction.Axis;
|
|
||||||
import net.minecraft.util.Direction.AxisDirection;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.IStringSerializable;
|
|
||||||
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.text.StringTextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
|
||||||
import net.minecraft.world.IWorld;
|
|
||||||
import net.minecraft.world.IWorldReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
|
||||||
|
|
||||||
public class LogisticalCasingBlock extends Block implements IWithTileEntity<LogisticalCasingTileEntity> {
|
|
||||||
|
|
||||||
public static final EnumProperty<Direction.Axis> AXIS = BlockStateProperties.AXIS;
|
|
||||||
public static final IProperty<Part> PART = EnumProperty.create("part", Part.class);
|
|
||||||
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
|
|
||||||
|
|
||||||
public LogisticalCasingBlock() {
|
|
||||||
super(Properties.from(Blocks.DARK_OAK_PLANKS));
|
|
||||||
setDefaultState(getDefaultState().with(PART, Part.NONE).with(AXIS, Axis.Y).with(ACTIVE, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
||||||
BlockState state = getDefaultState();
|
|
||||||
for (Direction face : Direction.values()) {
|
|
||||||
BlockState neighbour = context.getWorld().getBlockState(context.getPos().offset(face));
|
|
||||||
if (!AllBlocks.LOGISTICAL_CASING.typeOf(neighbour))
|
|
||||||
continue;
|
|
||||||
if (neighbour.get(PART) != Part.NONE && face.getAxis() != neighbour.get(AXIS))
|
|
||||||
continue;
|
|
||||||
state = state.with(PART, face.getAxisDirection() == AxisDirection.POSITIVE ? Part.START : Part.END);
|
|
||||||
state = state.with(AXIS, face.getAxis());
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) {
|
|
||||||
BlockState invState = world.getBlockState(neighbor);
|
|
||||||
|
|
||||||
if (!invState.hasTileEntity())
|
|
||||||
return;
|
|
||||||
TileEntity invTE = world.getTileEntity(neighbor);
|
|
||||||
|
|
||||||
LazyOptional<IItemHandler> inventory = invTE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
|
||||||
if (inventory.isPresent() && world instanceof IWorld) {
|
|
||||||
withTileEntityDo((IWorld) world, pos, te -> te.neighbourChanged(neighbor));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
|
||||||
boolean blockChanged = state.getBlock() != newState.getBlock();
|
|
||||||
if (state.hasTileEntity() && (blockChanged || !newState.hasTileEntity())) {
|
|
||||||
worldIn.removeTileEntity(pos);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (blockChanged) {
|
|
||||||
Part part = state.get(PART);
|
|
||||||
Direction facing = Direction.getFacingFromAxis(POSITIVE, state.get(AXIS));
|
|
||||||
if (part == Part.END || part == Part.MIDDLE)
|
|
||||||
worldIn.getPendingBlockTicks().scheduleTick(pos.offset(facing.getOpposite()), state.getBlock(), 1);
|
|
||||||
if (part == Part.START || part == Part.MIDDLE)
|
|
||||||
worldIn.getPendingBlockTicks().scheduleTick(pos.offset(facing), state.getBlock(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTileEntity(BlockState state) {
|
|
||||||
return state.get(ACTIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
|
||||||
return new LogisticalCasingTileEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
||||||
Part part = state.get(PART);
|
|
||||||
|
|
||||||
if (part == Part.NONE)
|
|
||||||
return AllShapes.LOGISTICAL_CASING_SINGLE_SHAPE;
|
|
||||||
|
|
||||||
if (part == Part.MIDDLE)
|
|
||||||
return AllShapes.LOGISTICAL_CASING_MIDDLE.get(state.get(AXIS));
|
|
||||||
|
|
||||||
Direction facing = VoxelShaper.axisAsFace(state.get(AXIS));
|
|
||||||
if (part == Part.END)
|
|
||||||
facing = facing.getOpposite();
|
|
||||||
|
|
||||||
return AllShapes.LOGISTICAL_CASING_CAP.get(facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState updatePostPlacement(BlockState state, Direction face, BlockState facingState, IWorld worldIn,
|
|
||||||
BlockPos currentPos, BlockPos facingPos) {
|
|
||||||
Part part = state.get(PART);
|
|
||||||
boolean neighbourPresent = AllBlocks.LOGISTICAL_CASING.typeOf(facingState);
|
|
||||||
boolean alongAxis = face.getAxis() == state.get(AXIS);
|
|
||||||
boolean positive = face.getAxisDirection() == AxisDirection.POSITIVE;
|
|
||||||
boolean neighbourAlongAxis = neighbourPresent
|
|
||||||
&& (facingState.get(PART) == Part.NONE || facingState.get(AXIS) == face.getAxis());
|
|
||||||
|
|
||||||
if (part == Part.NONE && neighbourPresent && neighbourAlongAxis) {
|
|
||||||
state = state.with(PART, positive ? Part.START : Part.END);
|
|
||||||
return state.with(AXIS, face.getAxis());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!alongAxis)
|
|
||||||
return state;
|
|
||||||
|
|
||||||
if (part == Part.END) {
|
|
||||||
if (positive && neighbourPresent && neighbourAlongAxis)
|
|
||||||
return state.with(PART, Part.MIDDLE);
|
|
||||||
if (!positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.NONE).with(AXIS, Axis.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part == Part.START) {
|
|
||||||
if (!positive && neighbourPresent && neighbourAlongAxis)
|
|
||||||
return state.with(PART, Part.MIDDLE);
|
|
||||||
if (positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.NONE).with(AXIS, Axis.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part == Part.MIDDLE) {
|
|
||||||
if (!positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.START);
|
|
||||||
if (positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.END);
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
|
||||||
BlockRayTraceResult hit) {
|
|
||||||
if (!player.getHeldItem(handIn).isEmpty())
|
|
||||||
return false;
|
|
||||||
if (worldIn.isRemote)
|
|
||||||
return true;
|
|
||||||
if (!state.get(ACTIVE))
|
|
||||||
player.sendStatusMessage(new StringTextComponent("Not Active").applyTextStyle(TextFormatting.RED), false);
|
|
||||||
else {
|
|
||||||
LogisticalCasingTileEntity tileEntity = (LogisticalCasingTileEntity) worldIn.getTileEntity(pos);
|
|
||||||
player.sendStatusMessage(new StringTextComponent("Controllers: " + tileEntity.controllers.toString())
|
|
||||||
.applyTextStyle(TextFormatting.GREEN), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
|
|
||||||
boolean blockChanged = state.getBlock() != oldState.getBlock();
|
|
||||||
if (blockChanged)
|
|
||||||
worldIn.getPendingBlockTicks().scheduleTick(pos, state.getBlock(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
|
|
||||||
synchronizeCasingGroup(worldIn, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void synchronizeCasingGroup(World world, BlockPos start) {
|
|
||||||
List<BlockPos> chain = LogisticalControllerBlock.collectCasings(world, start);
|
|
||||||
Set<BlockPos> controllers = new HashSet<>();
|
|
||||||
|
|
||||||
// Collect all Controllers
|
|
||||||
for (BlockPos pos : chain) {
|
|
||||||
BlockState casing = world.getBlockState(pos);
|
|
||||||
if (!casing.get(ACTIVE))
|
|
||||||
continue;
|
|
||||||
LogisticalCasingTileEntity te = (LogisticalCasingTileEntity) world.getTileEntity(pos);
|
|
||||||
if (te == null)
|
|
||||||
continue;
|
|
||||||
for (BlockPos controller : te.controllers) {
|
|
||||||
if (controller.withinDistance(te.getPos(), 1 + 1 / 512f))
|
|
||||||
controllers.add(controller);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Advertise all Controllers
|
|
||||||
for (BlockPos pos : chain) {
|
|
||||||
BlockState state = world.getBlockState(pos);
|
|
||||||
boolean shouldBeActive = !controllers.isEmpty();
|
|
||||||
if (state.get(ACTIVE) != shouldBeActive) {
|
|
||||||
if (!shouldBeActive) {
|
|
||||||
LogisticalCasingTileEntity te = (LogisticalCasingTileEntity) world.getTileEntity(pos);
|
|
||||||
te.controllers.forEach(te::detachController);
|
|
||||||
}
|
|
||||||
world.setBlockState(pos, state.with(ACTIVE, shouldBeActive));
|
|
||||||
}
|
|
||||||
if (!shouldBeActive)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
LogisticalCasingTileEntity te = (LogisticalCasingTileEntity) world.getTileEntity(pos);
|
|
||||||
if (te == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// detach missing
|
|
||||||
for (Iterator<BlockPos> iterator = te.controllers.iterator(); iterator.hasNext();) {
|
|
||||||
BlockPos controller = iterator.next();
|
|
||||||
if (controllers.contains(controller))
|
|
||||||
continue;
|
|
||||||
iterator.remove();
|
|
||||||
te.detachController(controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
// attach new
|
|
||||||
for (BlockPos controller : controllers) {
|
|
||||||
if (!te.controllers.contains(controller))
|
|
||||||
te.addController(controller);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
|
||||||
builder.add(AXIS, PART, ACTIVE);
|
|
||||||
super.fillStateContainer(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Part implements IStringSerializable {
|
|
||||||
START, MIDDLE, END, NONE;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name().toLowerCase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,144 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.nbt.ListNBT;
|
|
||||||
import net.minecraft.nbt.NBTUtil;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.common.util.Constants.NBT;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
|
||||||
|
|
||||||
public class LogisticalCasingTileEntity extends SyncedTileEntity {
|
|
||||||
|
|
||||||
Set<BlockPos> controllers = new HashSet<>();
|
|
||||||
|
|
||||||
public LogisticalCasingTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICAL_CASING.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean controllerPresent() {
|
|
||||||
if (controllers.isEmpty())
|
|
||||||
return false;
|
|
||||||
for (BlockPos blockPos : controllers) {
|
|
||||||
if (world.isBlockPresent(blockPos))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundNBT write(CompoundNBT compound) {
|
|
||||||
ListNBT contollerNBT = new ListNBT();
|
|
||||||
controllers.forEach(pos -> contollerNBT.add(NBTUtil.writeBlockPos(pos)));
|
|
||||||
compound.put("Controllers", contollerNBT);
|
|
||||||
return super.write(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(CompoundNBT compound) {
|
|
||||||
controllers.clear();
|
|
||||||
ListNBT controllerNBT = compound.getList("Controllers", NBT.TAG_COMPOUND);
|
|
||||||
controllerNBT.forEach(tag -> controllers.add(NBTUtil.readBlockPos((CompoundNBT) tag)));
|
|
||||||
super.read(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void neighbourChanged(BlockPos neighbour) {
|
|
||||||
if (!controllerPresent())
|
|
||||||
return;
|
|
||||||
for (LogisticalActorTileEntity controller : getControllers()) {
|
|
||||||
if (!(controller instanceof LogisticalInventoryControllerTileEntity))
|
|
||||||
continue;
|
|
||||||
((LogisticalInventoryControllerTileEntity) controller).inventoryChanged(neighbour);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addController(BlockPos pos) {
|
|
||||||
controllers.add(pos);
|
|
||||||
attachController(pos);
|
|
||||||
markDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeController(BlockPos pos) {
|
|
||||||
controllers.remove(pos);
|
|
||||||
detachController(pos);
|
|
||||||
markDirty();
|
|
||||||
|
|
||||||
if (controllers.isEmpty())
|
|
||||||
world.setBlockState(getPos(), getBlockState().with(LogisticalCasingBlock.ACTIVE, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void detachController(BlockPos pos) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
|
||||||
if (!(tileEntity instanceof LogisticalInventoryControllerTileEntity))
|
|
||||||
return;
|
|
||||||
for (Direction facing : Direction.values()) {
|
|
||||||
((LogisticalInventoryControllerTileEntity) tileEntity).detachInventory(getPos().offset(facing));
|
|
||||||
notifyAttachments(facing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void attachController(BlockPos pos) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(pos);
|
|
||||||
if (!(tileEntity instanceof LogisticalInventoryControllerTileEntity))
|
|
||||||
return;
|
|
||||||
for (Direction facing : Direction.values()) {
|
|
||||||
((LogisticalInventoryControllerTileEntity) tileEntity).inventoryChanged(getPos().offset(facing));
|
|
||||||
notifyAttachments(facing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void notifyAttachments(Direction d) {
|
|
||||||
BlockPos offset = pos.offset(d);
|
|
||||||
Block block = world.getBlockState(offset).getBlock();
|
|
||||||
if (block instanceof ILogisticalCasingAttachment)
|
|
||||||
((ILogisticalCasingAttachment) block).onCasingUpdated(world, offset, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
controllers.forEach(this::detachController);
|
|
||||||
super.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
|
|
||||||
if (!controllerPresent())
|
|
||||||
return LazyOptional.empty();
|
|
||||||
List<LogisticalActorTileEntity> TEs = getControllers();
|
|
||||||
if (controllers.isEmpty())
|
|
||||||
return LazyOptional.empty();
|
|
||||||
List<T> invs = TEs.stream().map(te -> te.getCasingCapability(cap, side).orElse(null))
|
|
||||||
.filter(Predicates.notNull()).filter(inv -> inv instanceof IItemHandlerModifiable)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
IItemHandlerModifiable[] params = new IItemHandlerModifiable[invs.size()];
|
|
||||||
invs.toArray(params);
|
|
||||||
return LazyOptional.of(() -> new CombinedInvWrapper(params)).cast();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<LogisticalActorTileEntity> getControllers() {
|
|
||||||
List<LogisticalActorTileEntity> TEs = new ArrayList<>(controllers.size());
|
|
||||||
for (BlockPos controllerPos : controllers) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(controllerPos);
|
|
||||||
if (tileEntity instanceof LogisticalActorTileEntity)
|
|
||||||
TEs.add((LogisticalActorTileEntity) tileEntity);
|
|
||||||
}
|
|
||||||
return TEs;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,289 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import static com.simibubi.create.AllItems.LOGISTICAL_CONTROLLER_CALCULATION;
|
|
||||||
import static com.simibubi.create.AllItems.LOGISTICAL_CONTROLLER_REQUEST;
|
|
||||||
import static com.simibubi.create.AllItems.LOGISTICAL_CONTROLLER_STORAGE;
|
|
||||||
import static com.simibubi.create.AllItems.LOGISTICAL_CONTROLLER_SUPPLY;
|
|
||||||
import static com.simibubi.create.AllItems.LOGISTICAL_CONTROLLER_TRANSACTIONS;
|
|
||||||
import static com.simibubi.create.modules.logistics.management.base.LogisticalCasingBlock.ACTIVE;
|
|
||||||
import static com.simibubi.create.modules.logistics.management.base.LogisticalCasingBlock.PART;
|
|
||||||
import static net.minecraft.state.properties.BlockStateProperties.AXIS;
|
|
||||||
import static net.minecraft.util.Direction.AxisDirection.POSITIVE;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.AllItems;
|
|
||||||
import com.simibubi.create.Create;
|
|
||||||
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
|
|
||||||
import com.simibubi.create.foundation.block.IWithContainer;
|
|
||||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
|
||||||
import com.simibubi.create.foundation.block.RenderUtilityBlock;
|
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalCasingBlock.Part;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.CalculationTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.RequestTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.StorageTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.SupplyTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.TransactionsTileEntity;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.block.DirectionalBlock;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.state.EnumProperty;
|
|
||||||
import net.minecraft.state.IProperty;
|
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.IStringSerializable;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
|
||||||
import net.minecraft.world.IWorldReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
|
||||||
|
|
||||||
public class LogisticalControllerBlock extends DirectionalBlock
|
|
||||||
implements IHaveNoBlockItem, IWithTileEntity<LogisticalActorTileEntity> {
|
|
||||||
|
|
||||||
public static final IProperty<Type> TYPE = EnumProperty.create("type", Type.class);
|
|
||||||
|
|
||||||
public LogisticalControllerBlock() {
|
|
||||||
super(Properties.from(Blocks.PISTON));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
|
||||||
builder.add(TYPE, FACING);
|
|
||||||
super.fillStateContainer(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTileEntity(BlockState state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
|
||||||
Type type = state.get(TYPE);
|
|
||||||
|
|
||||||
if (type == Type.SUPPLY)
|
|
||||||
return new SupplyTileEntity();
|
|
||||||
if (type == Type.REQUEST)
|
|
||||||
return new RequestTileEntity();
|
|
||||||
if (type == Type.STORAGE)
|
|
||||||
return new StorageTileEntity();
|
|
||||||
if (type == Type.CALCULATION)
|
|
||||||
return new CalculationTileEntity();
|
|
||||||
if (type == Type.TRANSACTIONS)
|
|
||||||
return new TransactionsTileEntity();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
|
||||||
if (!(placer instanceof PlayerEntity))
|
|
||||||
return;
|
|
||||||
PlayerEntity player = (PlayerEntity) placer;
|
|
||||||
for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++) {
|
|
||||||
ItemStack itemStack = player.inventory.getStackInSlot(slot);
|
|
||||||
if (!AllItems.LOGISTICAL_DIAL.typeOf(itemStack))
|
|
||||||
continue;
|
|
||||||
if (!itemStack.hasTag())
|
|
||||||
continue;
|
|
||||||
withTileEntityDo(worldIn, pos, te -> te.setNetworkId(itemStack.getTag().getUniqueId("NetworkID")));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
||||||
BlockState state = getDefaultState().with(FACING, context.getFace());
|
|
||||||
|
|
||||||
Item item = context.getItem().getItem();
|
|
||||||
if (item instanceof LogisticalControllerItem)
|
|
||||||
state = state.with(TYPE, ((LogisticalControllerItem) item).getType());
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getPickBlock(BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos,
|
|
||||||
PlayerEntity player) {
|
|
||||||
return getItem(world, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ItemStack> getDrops(BlockState state, net.minecraft.world.storage.loot.LootContext.Builder builder) {
|
|
||||||
return Arrays.asList(getItem(builder.getWorld(), BlockPos.ZERO, state));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItem(IBlockReader worldIn, BlockPos pos, BlockState state) {
|
|
||||||
for (AllItems item : Arrays.asList(LOGISTICAL_CONTROLLER_CALCULATION, LOGISTICAL_CONTROLLER_REQUEST,
|
|
||||||
LOGISTICAL_CONTROLLER_STORAGE, LOGISTICAL_CONTROLLER_SUPPLY, LOGISTICAL_CONTROLLER_TRANSACTIONS)) {
|
|
||||||
if (((LogisticalControllerItem) item.get()).getType() == state.get(TYPE))
|
|
||||||
return item.asStack();
|
|
||||||
}
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
|
||||||
Direction facing = state.get(FACING);
|
|
||||||
BlockPos offset = pos.offset(facing.getOpposite());
|
|
||||||
BlockState blockState = worldIn.getBlockState(offset);
|
|
||||||
boolean isCasing = AllBlocks.LOGISTICAL_CASING.typeOf(blockState);
|
|
||||||
|
|
||||||
return isCasing;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTranslationKey() {
|
|
||||||
return "block." + Create.ID + ".logistical_controller";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getControllerTypeTranslationKey(BlockState state) {
|
|
||||||
return "item." + Create.ID + ".logistical_controller_" + state.get(TYPE).name().toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
|
||||||
BlockRayTraceResult hit) {
|
|
||||||
if (player.isSneaking() || !player.isAllowEdit())
|
|
||||||
return false;
|
|
||||||
if (!state.hasTileEntity())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
TileEntity te = worldIn.getTileEntity(pos);
|
|
||||||
if (!(te instanceof LogisticalInventoryControllerTileEntity))
|
|
||||||
return false;
|
|
||||||
if (state.get(TYPE) == Type.CALCULATION)
|
|
||||||
return false;
|
|
||||||
if (AllItems.LOGISTICAL_DIAL.typeOf(player.getHeldItem(handIn)))
|
|
||||||
return false;
|
|
||||||
if (worldIn.isRemote)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
IWithContainer<?, ?> cte = (IWithContainer<?, ?>) te;
|
|
||||||
NetworkHooks.openGui((ServerPlayerEntity) player, cte, cte::sendToContainer);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
|
|
||||||
BlockPos start = pos.offset(state.get(FACING).getOpposite());
|
|
||||||
List<BlockPos> toUpdate = collectCasings(worldIn, start);
|
|
||||||
|
|
||||||
for (BlockPos blockPos : toUpdate) {
|
|
||||||
worldIn.setBlockState(blockPos, worldIn.getBlockState(blockPos).with(ACTIVE, true));
|
|
||||||
LogisticalCasingTileEntity tileEntity = (LogisticalCasingTileEntity) worldIn.getTileEntity(blockPos);
|
|
||||||
tileEntity.addController(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
|
||||||
boolean blockChanged = state.getBlock() != newState.getBlock() || state.get(TYPE) != newState.get(TYPE);
|
|
||||||
|
|
||||||
if (blockChanged) {
|
|
||||||
BlockPos start = pos.offset(state.get(FACING).getOpposite());
|
|
||||||
List<BlockPos> toUpdate = collectCasings(worldIn, start);
|
|
||||||
|
|
||||||
for (BlockPos blockPos : toUpdate) {
|
|
||||||
if (!worldIn.getBlockState(blockPos).get(ACTIVE))
|
|
||||||
continue;
|
|
||||||
LogisticalCasingTileEntity tileEntity = (LogisticalCasingTileEntity) worldIn.getTileEntity(blockPos);
|
|
||||||
tileEntity.removeController(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.hasTileEntity() && blockChanged) {
|
|
||||||
worldIn.removeTileEntity(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<BlockPos> collectCasings(World worldIn, BlockPos start) {
|
|
||||||
BlockState casing = worldIn.getBlockState(start);
|
|
||||||
if (!AllBlocks.LOGISTICAL_CASING.typeOf(casing))
|
|
||||||
return Collections.emptyList();
|
|
||||||
List<BlockPos> casings = new ArrayList<>();
|
|
||||||
casings.add(start);
|
|
||||||
if (casing.get(PART) != Part.NONE) {
|
|
||||||
Direction casingDirection = Direction.getFacingFromAxis(POSITIVE, casing.get(AXIS));
|
|
||||||
BlockPos search = start;
|
|
||||||
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
|
||||||
if (worldIn.getBlockState(search).get(PART) == Part.START)
|
|
||||||
break;
|
|
||||||
search = search.offset(casingDirection.getOpposite());
|
|
||||||
if (!AllBlocks.LOGISTICAL_CASING.typeOf(worldIn.getBlockState(search)))
|
|
||||||
break;
|
|
||||||
casings.add(search);
|
|
||||||
}
|
|
||||||
search = start;
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
|
||||||
if (worldIn.getBlockState(search).get(PART) == Part.END)
|
|
||||||
break;
|
|
||||||
search = search.offset(casingDirection);
|
|
||||||
if (!AllBlocks.LOGISTICAL_CASING.typeOf(worldIn.getBlockState(search)))
|
|
||||||
break;
|
|
||||||
casings.add(search);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return casings;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
|
||||||
boolean isMoving) {
|
|
||||||
if (state.isValidPosition(worldIn, pos))
|
|
||||||
return;
|
|
||||||
|
|
||||||
TileEntity tileentity = state.hasTileEntity() ? worldIn.getTileEntity(pos) : null;
|
|
||||||
spawnDrops(state, worldIn, pos, tileentity);
|
|
||||||
worldIn.removeBlock(pos, false);
|
|
||||||
|
|
||||||
for (Direction direction : Direction.values())
|
|
||||||
worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
||||||
return AllShapes.LOGISTICAL_CONTROLLER.get(state.get(FACING));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class LogisticalControllerIndicatorBlock extends RenderUtilityBlock {
|
|
||||||
@Override
|
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
|
||||||
builder.add(TYPE, FACING);
|
|
||||||
super.fillStateContainer(builder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Type implements IStringSerializable {
|
|
||||||
SUPPLY, REQUEST, STORAGE, CALCULATION, TRANSACTIONS;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name().toLowerCase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.Create;
|
|
||||||
import com.simibubi.create.foundation.item.IAddedByOther;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock.Type;
|
|
||||||
|
|
||||||
import net.minecraft.item.BlockItem;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.NonNullList;
|
|
||||||
|
|
||||||
public class LogisticalControllerItem extends BlockItem implements IAddedByOther {
|
|
||||||
|
|
||||||
private Type type;
|
|
||||||
|
|
||||||
public LogisticalControllerItem(Properties builder, Type type) {
|
|
||||||
super(AllBlocks.LOGISTICAL_CONTROLLER.get(), builder);
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
|
||||||
if (this.isInGroup(group)) {
|
|
||||||
items.add(new ItemStack(this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTranslationKey(ItemStack stack) {
|
|
||||||
return "item." + Create.ID + "." + getRegistryName().getPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
|
||||||
|
|
||||||
public abstract class LogisticalControllerTileEntity extends LogisticalActorTileEntity {
|
|
||||||
|
|
||||||
public LogisticalControllerTileEntity(TileEntityType<?> tileEntityTypeIn) {
|
|
||||||
super(tileEntityTypeIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasFastRenderer() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import static com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock.TYPE;
|
|
||||||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.foundation.block.render.ColoredOverlayTileEntityRenderer;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
|
|
||||||
public class LogisticalControllerTileEntityRenderer
|
|
||||||
extends ColoredOverlayTileEntityRenderer<LogisticalActorTileEntity> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getColor(LogisticalActorTileEntity te, float partialTicks) {
|
|
||||||
return te.getColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockState getOverlayState(LogisticalActorTileEntity te) {
|
|
||||||
BlockState state = te.getBlockState();
|
|
||||||
return AllBlocks.LOGISTICAL_CONTROLLER_INDICATOR.get().getDefaultState().with(FACING, state.get(FACING))
|
|
||||||
.with(TYPE, state.get(TYPE));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.Ingredient;
|
|
||||||
|
|
||||||
public abstract class LogisticalTask implements Comparable<LogisticalTask> {
|
|
||||||
|
|
||||||
public enum Priority {
|
|
||||||
HIGH, MEDIUM, LOW
|
|
||||||
}
|
|
||||||
|
|
||||||
Priority priority = Priority.LOW;
|
|
||||||
public String targetAddress;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(LogisticalTask o) {
|
|
||||||
return priority.compareTo(o.priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SupplyTask extends LogisticalTask {
|
|
||||||
public List<Pair<Ingredient, Integer>> items;
|
|
||||||
private String display;
|
|
||||||
|
|
||||||
public SupplyTask(ItemStackEntry requested, String address) {
|
|
||||||
items = Arrays.asList(Pair.of(Ingredient.fromStacks(requested.stack), requested.amount));
|
|
||||||
targetAddress = address;
|
|
||||||
display = "Supply " + requested.amount + "x " + requested.stack.getItem().getName().getFormattedText()
|
|
||||||
+ " -> " + address;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return display;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DepositTask extends LogisticalTask {
|
|
||||||
public ItemStack stack;
|
|
||||||
|
|
||||||
public DepositTask(ItemStack stack) {
|
|
||||||
this.stack = stack.copy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,127 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.base;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
|
||||||
import com.simibubi.create.foundation.utility.VoxelShaper;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
|
||||||
import net.minecraft.state.BooleanProperty;
|
|
||||||
import net.minecraft.state.EnumProperty;
|
|
||||||
import net.minecraft.state.IProperty;
|
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.Direction.Axis;
|
|
||||||
import net.minecraft.util.Direction.AxisDirection;
|
|
||||||
import net.minecraft.util.IStringSerializable;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
|
||||||
import net.minecraft.world.IWorld;
|
|
||||||
|
|
||||||
public class NewLogisticalCasingBlock extends Block {
|
|
||||||
|
|
||||||
public static final EnumProperty<Direction.Axis> AXIS = BlockStateProperties.AXIS;
|
|
||||||
public static final IProperty<Part> PART = EnumProperty.create("part", Part.class);
|
|
||||||
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
|
|
||||||
|
|
||||||
public NewLogisticalCasingBlock() {
|
|
||||||
super(Properties.from(Blocks.DARK_OAK_PLANKS));
|
|
||||||
setDefaultState(getDefaultState().with(PART, Part.NONE).with(AXIS, Axis.Y).with(ACTIVE, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
||||||
BlockState state = getDefaultState();
|
|
||||||
for (Direction face : Direction.values()) {
|
|
||||||
BlockState neighbour = context.getWorld().getBlockState(context.getPos().offset(face));
|
|
||||||
if (!AllBlocks.LOGISTICAL_CASING.typeOf(neighbour))
|
|
||||||
continue;
|
|
||||||
if (neighbour.get(PART) != Part.NONE && face.getAxis() != neighbour.get(AXIS))
|
|
||||||
continue;
|
|
||||||
state = state.with(PART, face.getAxisDirection() == AxisDirection.POSITIVE ? Part.START : Part.END);
|
|
||||||
state = state.with(AXIS, face.getAxis());
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
||||||
Part part = state.get(PART);
|
|
||||||
|
|
||||||
if (part == Part.NONE)
|
|
||||||
return AllShapes.LOGISTICAL_CASING_SINGLE_SHAPE;
|
|
||||||
|
|
||||||
if (part == Part.MIDDLE)
|
|
||||||
return AllShapes.LOGISTICAL_CASING_MIDDLE.get(state.get(AXIS));
|
|
||||||
|
|
||||||
Direction facing = VoxelShaper.axisAsFace(state.get(AXIS));
|
|
||||||
if (part == Part.END)
|
|
||||||
facing = facing.getOpposite();
|
|
||||||
|
|
||||||
return AllShapes.LOGISTICAL_CASING_CAP.get(facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState updatePostPlacement(BlockState state, Direction face, BlockState facingState, IWorld worldIn,
|
|
||||||
BlockPos currentPos, BlockPos facingPos) {
|
|
||||||
Part part = state.get(PART);
|
|
||||||
boolean neighbourPresent = AllBlocks.LOGISTICAL_CASING.typeOf(facingState);
|
|
||||||
boolean alongAxis = face.getAxis() == state.get(AXIS);
|
|
||||||
boolean positive = face.getAxisDirection() == AxisDirection.POSITIVE;
|
|
||||||
boolean neighbourAlongAxis = neighbourPresent
|
|
||||||
&& (facingState.get(PART) == Part.NONE || facingState.get(AXIS) == face.getAxis());
|
|
||||||
|
|
||||||
if (part == Part.NONE && neighbourPresent && neighbourAlongAxis) {
|
|
||||||
state = state.with(PART, positive ? Part.START : Part.END);
|
|
||||||
return state.with(AXIS, face.getAxis());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!alongAxis)
|
|
||||||
return state;
|
|
||||||
|
|
||||||
if (part == Part.END) {
|
|
||||||
if (positive && neighbourPresent && neighbourAlongAxis)
|
|
||||||
return state.with(PART, Part.MIDDLE);
|
|
||||||
if (!positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.NONE).with(AXIS, Axis.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part == Part.START) {
|
|
||||||
if (!positive && neighbourPresent && neighbourAlongAxis)
|
|
||||||
return state.with(PART, Part.MIDDLE);
|
|
||||||
if (positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.NONE).with(AXIS, Axis.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (part == Part.MIDDLE) {
|
|
||||||
if (!positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.START);
|
|
||||||
if (positive && !neighbourPresent)
|
|
||||||
return state.with(PART, Part.END);
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
|
||||||
builder.add(AXIS, PART, ACTIVE);
|
|
||||||
super.fillStateContainer(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Part implements IStringSerializable {
|
|
||||||
START, MIDDLE, END, NONE;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name().toLowerCase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
|
|
||||||
public class CalculationTileEntity extends LogisticalInventoryControllerTileEntity {
|
|
||||||
|
|
||||||
public CalculationTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICAL_CALCULATION_CONTROLLER.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ShippingInventory createInventory() {
|
|
||||||
return new ShippingInventory(false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.packet.TileEntityConfigurationPacket;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity.Priority;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity.ShippingInventory;
|
|
||||||
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
|
|
||||||
public class LogisticalControllerConfigurationPacket
|
|
||||||
extends TileEntityConfigurationPacket<LogisticalInventoryControllerTileEntity> {
|
|
||||||
|
|
||||||
String address;
|
|
||||||
int filterAmount;
|
|
||||||
Priority priority;
|
|
||||||
boolean active;
|
|
||||||
|
|
||||||
public LogisticalControllerConfigurationPacket(BlockPos pos, String address, int filterAmount,
|
|
||||||
Priority priority, boolean active) {
|
|
||||||
super(pos);
|
|
||||||
this.address = address;
|
|
||||||
this.filterAmount = filterAmount;
|
|
||||||
this.priority = priority;
|
|
||||||
this.active = active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogisticalControllerConfigurationPacket(PacketBuffer buffer) {
|
|
||||||
super(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void writeSettings(PacketBuffer buffer) {
|
|
||||||
buffer.writeString(address, 2048);
|
|
||||||
buffer.writeInt(filterAmount);
|
|
||||||
buffer.writeInt(priority.ordinal());
|
|
||||||
buffer.writeBoolean(active);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void readSettings(PacketBuffer buffer) {
|
|
||||||
address = buffer.readString(2048);
|
|
||||||
filterAmount = buffer.readInt();
|
|
||||||
priority = Priority.values()[buffer.readInt()];
|
|
||||||
active = buffer.readBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void applySettings(LogisticalInventoryControllerTileEntity te) {
|
|
||||||
if (!address.isEmpty()) {
|
|
||||||
te.address = address;
|
|
||||||
if (te.getNetwork() != null)
|
|
||||||
te.getNetwork().reAdvertiseReceivers();
|
|
||||||
}
|
|
||||||
te.priority = priority;
|
|
||||||
te.isActive = active;
|
|
||||||
te.shippingInventory.ifPresent(inv -> {
|
|
||||||
ShippingInventory sInv = (ShippingInventory) inv;
|
|
||||||
sInv.filterAmount = filterAmount;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllContainers;
|
|
||||||
import com.simibubi.create.foundation.block.AbstractTileEntityContainer;
|
|
||||||
import com.simibubi.create.foundation.type.CombinedCountedItemsList;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.inventory.container.ClickType;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraftforge.items.SlotItemHandler;
|
|
||||||
|
|
||||||
public class LogisticalInventoryControllerContainer
|
|
||||||
extends AbstractTileEntityContainer<LogisticalInventoryControllerTileEntity> {
|
|
||||||
|
|
||||||
public CombinedCountedItemsList<String> allItems = new CombinedCountedItemsList<>();
|
|
||||||
|
|
||||||
public LogisticalInventoryControllerContainer(int id, PlayerInventory inv, PacketBuffer extraData) {
|
|
||||||
super(AllContainers.LOGISTICAL_CONTROLLER, id, inv, extraData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogisticalInventoryControllerContainer(int id, PlayerInventory inv,
|
|
||||||
LogisticalInventoryControllerTileEntity te) {
|
|
||||||
super(AllContainers.LOGISTICAL_CONTROLLER, id, inv, te);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
addSlot(new SlotItemHandler(te.getInventory(), 0, 135, 32));
|
|
||||||
addSlot(new SlotItemHandler(te.getInventory(), 1, 135 + 18, 32));
|
|
||||||
addSlot(new SlotItemHandler(te.getInventory(), 2, 84, 29));
|
|
||||||
addPlayerSlots(48, 118);
|
|
||||||
detectAndSendChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) {
|
|
||||||
if (slotId != 2)
|
|
||||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
|
||||||
ItemStack item = player.inventory.getItemStack();
|
|
||||||
ItemStack copy = item.copy();
|
|
||||||
|
|
||||||
if (copy.isEmpty()) {
|
|
||||||
te.getInventory().extractItem(2, 1, false);
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
copy.setCount(1);
|
|
||||||
te.getInventory().extractItem(2, 1, false);
|
|
||||||
te.getInventory().insertItem(2, copy, false);
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,252 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import static com.simibubi.create.ScreenResources.I_PRIORITY_HIGH;
|
|
||||||
import static com.simibubi.create.ScreenResources.I_PRIORITY_LOW;
|
|
||||||
import static com.simibubi.create.ScreenResources.I_PRIORITY_VERY_HIGH;
|
|
||||||
import static com.simibubi.create.ScreenResources.I_PRIORITY_VERY_LOW;
|
|
||||||
import static com.simibubi.create.ScreenResources.LOGISTICAL_CONTROLLER;
|
|
||||||
import static com.simibubi.create.ScreenResources.LOGISTICAL_CONTROLLER_TRIM;
|
|
||||||
import static com.simibubi.create.ScreenResources.PLAYER_INVENTORY;
|
|
||||||
import static com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock.TYPE;
|
|
||||||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.AllItems;
|
|
||||||
import com.simibubi.create.AllPackets;
|
|
||||||
import com.simibubi.create.ScreenResources;
|
|
||||||
import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen;
|
|
||||||
import com.simibubi.create.foundation.gui.ScreenElementRenderer;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.IconButton;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.Indicator;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.Indicator.State;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.ScrollInput;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput;
|
|
||||||
import com.simibubi.create.foundation.utility.ColorHelper;
|
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity.Priority;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock.Type;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.client.util.InputMappings;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
|
|
||||||
public class LogisticalInventoryControllerScreen
|
|
||||||
extends AbstractSimiContainerScreen<LogisticalInventoryControllerContainer> {
|
|
||||||
|
|
||||||
private BlockState controllerState;
|
|
||||||
private BlockState controllerLightState;
|
|
||||||
private ItemStack nameTagItem;
|
|
||||||
private ItemStack boxItem;
|
|
||||||
|
|
||||||
private Type controllerType;
|
|
||||||
|
|
||||||
private ScrollInput priorityInput;
|
|
||||||
private TextFieldWidget addressInput;
|
|
||||||
private IconButton passiveModeButton;
|
|
||||||
private IconButton activeModeButton;
|
|
||||||
private Indicator passiveModeIndicator;
|
|
||||||
private Indicator activeModeIndicator;
|
|
||||||
private IconButton confirmButton;
|
|
||||||
private ScrollInput filterAmountInput;
|
|
||||||
|
|
||||||
private final List<ScreenResources> priorityIcons = Arrays.asList(I_PRIORITY_VERY_HIGH, I_PRIORITY_HIGH,
|
|
||||||
I_PRIORITY_LOW, I_PRIORITY_VERY_LOW);
|
|
||||||
private final List<String> priorityOptions = Lang.translatedOptions("logistics.priority", "highest", "high", "low",
|
|
||||||
"lowest");
|
|
||||||
|
|
||||||
private String priority = Lang.translate("logistics.priority");
|
|
||||||
private String requestedItemCount = Lang.translate("gui.requester.requestedItemCount");
|
|
||||||
private String activeMode = Lang.translate("gui.logistical_controller.active_mode");
|
|
||||||
private String passiveMode = Lang.translate("gui.logistical_controller.passive_mode");
|
|
||||||
private String storagePassiveModeOnly = Lang.translate("gui.storage.passiveModeOnly");
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
public LogisticalInventoryControllerScreen(LogisticalInventoryControllerContainer container, PlayerInventory inv,
|
|
||||||
ITextComponent title) {
|
|
||||||
super(container, inv, title);
|
|
||||||
this.title = I18n
|
|
||||||
.format(LogisticalControllerBlock.getControllerTypeTranslationKey(container.te.getBlockState()));
|
|
||||||
controllerState = container.te.getBlockState().with(BlockStateProperties.FACING, Direction.SOUTH);
|
|
||||||
controllerType = controllerState.get(LogisticalControllerBlock.TYPE);
|
|
||||||
controllerLightState = AllBlocks.LOGISTICAL_CONTROLLER_INDICATOR.get().getDefaultState()
|
|
||||||
.with(FACING, controllerState.get(FACING)).with(TYPE, controllerState.get(TYPE));
|
|
||||||
nameTagItem = new ItemStack(Items.NAME_TAG);
|
|
||||||
boxItem = AllItems.CARDBOARD_BOX_1410.asStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
setWindowSize(256, 200);
|
|
||||||
super.init();
|
|
||||||
widgets.clear();
|
|
||||||
|
|
||||||
int x = guiLeft;
|
|
||||||
int y = guiTop;
|
|
||||||
|
|
||||||
addressInput = new TextFieldWidget(font, x + 29, y + 62, 116, 8, "");
|
|
||||||
addressInput.setTextColor(0xFFFFFF);
|
|
||||||
addressInput.setDisabledTextColour(-1);
|
|
||||||
addressInput.setText(container.te.address);
|
|
||||||
addressInput.setEnableBackgroundDrawing(false);
|
|
||||||
addressInput.setMaxStringLength(256);
|
|
||||||
addressInput.setResponder(this::onAddressInputChanged);
|
|
||||||
addressInput.setFocused2(false);
|
|
||||||
|
|
||||||
priorityInput = new SelectionScrollInput(x + 49, y + 31, 18, 18).forOptions(priorityOptions).titled(priority)
|
|
||||||
.setState(container.te.getPriority().ordinal());
|
|
||||||
filterAmountInput = new ScrollInput(x + 85, y + 46, 15, 8).withRange(1, 1025).withShiftStep(64)
|
|
||||||
.titled(requestedItemCount).setState(container.te.getInventory().filterAmount);
|
|
||||||
|
|
||||||
passiveModeButton = new IconButton(x + 8, y + 31, ScreenResources.I_PASSIVE);
|
|
||||||
passiveModeButton.setToolTip(passiveMode);
|
|
||||||
if (controllerType == Type.STORAGE)
|
|
||||||
passiveModeButton.getToolTip().add(TextFormatting.GOLD + storagePassiveModeOnly);
|
|
||||||
passiveModeIndicator = new Indicator(x + 8, y + 26, "");
|
|
||||||
activeModeButton = new IconButton(x + 26, y + 31, ScreenResources.I_ACTIVE);
|
|
||||||
activeModeButton.setToolTip(activeMode);
|
|
||||||
activeModeIndicator = new Indicator(x + 26, y + 26, "");
|
|
||||||
setPassiveMode(!container.te.isActive);
|
|
||||||
|
|
||||||
confirmButton = new IconButton(x + 152, y + 57, ScreenResources.I_CONFIRM);
|
|
||||||
|
|
||||||
widgets.addAll(Arrays.asList(priorityInput, addressInput, passiveModeButton, passiveModeIndicator,
|
|
||||||
activeModeButton, activeModeIndicator, confirmButton));
|
|
||||||
if (controllerType == Type.REQUEST)
|
|
||||||
widgets.add(filterAmountInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWindow(int mouseX, int mouseY, float partialTicks) {
|
|
||||||
int x = guiLeft;
|
|
||||||
int y = guiTop;
|
|
||||||
|
|
||||||
LOGISTICAL_CONTROLLER_TRIM.draw(this, x, y);
|
|
||||||
LOGISTICAL_CONTROLLER_TRIM.draw(this, x, y + 6 + LOGISTICAL_CONTROLLER.height);
|
|
||||||
|
|
||||||
ColorHelper.glColor(container.te.getColor());
|
|
||||||
LOGISTICAL_CONTROLLER.draw(this, x, y + 6);
|
|
||||||
ColorHelper.glResetColor();
|
|
||||||
|
|
||||||
ScreenResources.BIG_SLOT.draw(this, x + 79, y + 24);
|
|
||||||
ScreenResources.SHIPPING_SLOT.draw(this, x + 134, y + 28);
|
|
||||||
ScreenResources.RECEIVING_SLOT.draw(this, x + 134 + 18, y + 28);
|
|
||||||
PLAYER_INVENTORY.draw(this, x + (getXSize() - PLAYER_INVENTORY.width) / 2, y + 100);
|
|
||||||
|
|
||||||
ScreenResources priorityIcon = priorityIcons.get(priorityInput.getState());
|
|
||||||
ColorHelper.glColor(0);
|
|
||||||
priorityIcon.draw(this, x + 51, y + 33);
|
|
||||||
ColorHelper.glResetColor();
|
|
||||||
priorityIcon.draw(this, x + 50, y + 32);
|
|
||||||
|
|
||||||
if (controllerType == Type.REQUEST) {
|
|
||||||
ScreenResources.ITEM_COUNT_SCROLLAREA.draw(this, x + 81, y + 45);
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
double scale = getItemCountTextScale();
|
|
||||||
String text = "" + filterAmountInput.getState();
|
|
||||||
GlStateManager.translated(x + 91.5, y + 53, 0);
|
|
||||||
GlStateManager.scaled(scale, scale, 0);
|
|
||||||
int guiScaleFactor = (int) minecraft.mainWindow.getGuiScaleFactor();
|
|
||||||
GlStateManager.translated((-font.getStringWidth(text)) / 2,
|
|
||||||
-font.FONT_HEIGHT + (guiScaleFactor > 1 ? 1 : 1.75f), 0);
|
|
||||||
font.drawStringWithShadow(text, 0, 0, 0xFFFFFF);
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
font.drawString(playerInventory.getDisplayName().getFormattedText(), x + 48, y + 106, 0x666666);
|
|
||||||
font.drawStringWithShadow(title, x + (LOGISTICAL_CONTROLLER.width - font.getStringWidth(title)) / 2, y + 9,
|
|
||||||
ColorHelper.mixColors(0xFFFFFF, container.te.getColor(), .25f));
|
|
||||||
|
|
||||||
ScreenElementRenderer.renderBlock(() -> {
|
|
||||||
transformRenderedBlocks();
|
|
||||||
return controllerState;
|
|
||||||
});
|
|
||||||
|
|
||||||
ScreenElementRenderer.renderBlock(() -> {
|
|
||||||
transformRenderedBlocks();
|
|
||||||
return controllerLightState;
|
|
||||||
}, container.te.getColor());
|
|
||||||
|
|
||||||
ColorHelper.glResetColor();
|
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
|
||||||
itemRenderer.renderItemIntoGUI(nameTagItem, x + 7, y + 57);
|
|
||||||
itemRenderer.renderItemIntoGUI(boxItem, x + 116, y + 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onAddressInputChanged(String s) {
|
|
||||||
confirmButton.active = !s.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) {
|
|
||||||
InputMappings.Input mouseKey = InputMappings.getInputByCode(code, p_keyPressed_2_);
|
|
||||||
boolean closingScreen = this.minecraft.gameSettings.keyBindInventory.isActiveAndMatches(mouseKey);
|
|
||||||
boolean enter = code == GLFW.GLFW_KEY_ENTER;
|
|
||||||
|
|
||||||
if (closingScreen && addressInput.isFocused())
|
|
||||||
return true;
|
|
||||||
if (enter && addressInput.isFocused())
|
|
||||||
addressInput.changeFocus(false);
|
|
||||||
|
|
||||||
return super.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(double x, double y, int button) {
|
|
||||||
if (confirmButton.active && confirmButton.isHovered())
|
|
||||||
minecraft.displayGuiScreen(null);
|
|
||||||
if (activeModeButton.active && activeModeButton.isHovered())
|
|
||||||
setPassiveMode(false);
|
|
||||||
if (passiveModeButton.active && passiveModeButton.isHovered())
|
|
||||||
setPassiveMode(true);
|
|
||||||
|
|
||||||
return super.mouseClicked(x, y, button);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassiveMode(boolean passive) {
|
|
||||||
if (controllerType == Type.STORAGE) {
|
|
||||||
activeModeButton.active = passiveModeButton.active = false;
|
|
||||||
activeModeIndicator.state = State.OFF;
|
|
||||||
passiveModeIndicator.state = State.ON;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
activeModeButton.active = passive;
|
|
||||||
passiveModeButton.active = !passive;
|
|
||||||
activeModeIndicator.state = passive ? State.OFF : State.ON;
|
|
||||||
passiveModeIndicator.state = !passive ? State.OFF : State.ON;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removed() {
|
|
||||||
boolean active = !activeModeButton.active;
|
|
||||||
Priority priorityOut = Priority.values()[priorityInput.getState()];
|
|
||||||
String text = addressInput.getText();
|
|
||||||
AllPackets.channel.sendToServer(new LogisticalControllerConfigurationPacket(container.te.getPos(), text,
|
|
||||||
filterAmountInput.getState(), priorityOut, active));
|
|
||||||
super.removed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void transformRenderedBlocks() {
|
|
||||||
GlStateManager.translated(guiLeft + 205, guiTop + 70, 0);
|
|
||||||
GlStateManager.rotatef(50, -.5f, 1, -.2f);
|
|
||||||
GlStateManager.rotatef(190, 0, 1, 0);
|
|
||||||
GlStateManager.scaled(1.25, 1.25, 1.25);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,452 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.block.IWithContainer;
|
|
||||||
import com.simibubi.create.foundation.item.ItemHelper;
|
|
||||||
import com.simibubi.create.foundation.type.CombinedCountedItemsList;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
|
|
||||||
import com.simibubi.create.modules.logistics.item.CardboardBoxItem;
|
|
||||||
import com.simibubi.create.modules.logistics.management.LogisticalNetwork;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalCasingTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerBlock;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalControllerTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalTask;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.DepositTask;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.SupplyTask;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.crafting.Ingredient;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
|
||||||
import net.minecraftforge.items.ItemStackHandler;
|
|
||||||
|
|
||||||
public abstract class LogisticalInventoryControllerTileEntity extends LogisticalControllerTileEntity
|
|
||||||
implements IWithContainer<LogisticalInventoryControllerTileEntity, LogisticalInventoryControllerContainer> {
|
|
||||||
|
|
||||||
protected Map<BlockPos, ConnectedInventory> observedInventories = new HashMap<>();
|
|
||||||
protected Map<IItemHandler, ConnectedInventory> inventoryByHandler = new HashMap<>();
|
|
||||||
protected CombinedCountedItemsList<IItemHandler> allItems = new CombinedCountedItemsList<>();
|
|
||||||
protected boolean inventorySetDirty;
|
|
||||||
|
|
||||||
protected LazyOptional<IItemHandler> shippingInventory;
|
|
||||||
protected boolean tryInsertBox;
|
|
||||||
|
|
||||||
public boolean isActive;
|
|
||||||
|
|
||||||
public LogisticalInventoryControllerTileEntity(TileEntityType<?> tileEntityTypeIn) {
|
|
||||||
super(tileEntityTypeIn);
|
|
||||||
this.shippingInventory = LazyOptional.of(this::createInventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(CompoundNBT compound) {
|
|
||||||
super.read(compound);
|
|
||||||
if (compound.contains("ShippingInventory")) {
|
|
||||||
ShippingInventory inv = (ShippingInventory) shippingInventory.orElse(null);
|
|
||||||
inv.deserializeNBT(compound.getCompound("ShippingInventory"));
|
|
||||||
}
|
|
||||||
isActive = compound.getBoolean("Active");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void inventoryChanged(BlockPos pos) {
|
|
||||||
removeInvalidatedInventories();
|
|
||||||
TileEntity invTE = world.getTileEntity(pos);
|
|
||||||
if (invTE == null)
|
|
||||||
return;
|
|
||||||
if (invTE instanceof LogisticalCasingTileEntity)
|
|
||||||
return;
|
|
||||||
|
|
||||||
LazyOptional<IItemHandler> inventory = invTE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
|
||||||
if (!observedInventories.containsKey(pos)) {
|
|
||||||
addInventory(pos, inventory);
|
|
||||||
notifyIndexers(observedInventories.get(pos).countedItems);
|
|
||||||
} else {
|
|
||||||
if (inventoryByHandler.containsKey(inventory.orElse(null))) {
|
|
||||||
List<ItemStackEntry> localChanges = observedInventories.get(pos).refresh();
|
|
||||||
CountedItemsList changes = new CountedItemsList();
|
|
||||||
for (ItemStackEntry entry : localChanges)
|
|
||||||
changes.add(entry.stack, allItems.get().getItemCount(entry.stack));
|
|
||||||
notifyIndexers(changes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkTasks = true;
|
|
||||||
tryInsertBox = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void detachInventory(BlockPos pos) {
|
|
||||||
observedInventories.remove(pos);
|
|
||||||
inventorySetDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addInventory(BlockPos pos, LazyOptional<IItemHandler> inventory) {
|
|
||||||
observedInventories.put(pos, new ConnectedInventory(inventory));
|
|
||||||
inventorySetDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void notifyIndexers(CountedItemsList updates) {
|
|
||||||
if (network == null)
|
|
||||||
return;
|
|
||||||
network.indexers.forEach(indexer -> indexer.handleUpdatedController(address, updates));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
|
|
||||||
if (taskCooldown > 0 || world.isRemote)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (tryInsertBox) {
|
|
||||||
tryInsertBox = false;
|
|
||||||
tryInsertBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkTasks) {
|
|
||||||
checkTasks = false;
|
|
||||||
if (getNetwork() == null)
|
|
||||||
return;
|
|
||||||
checkTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
taskCooldown = COOLDOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tryInsertBox() {
|
|
||||||
if (!canReceive())
|
|
||||||
return;
|
|
||||||
|
|
||||||
ShippingInventory inventory = getInventory();
|
|
||||||
ItemStack box = inventory.getStackInSlot(ShippingInventory.RECEIVING);
|
|
||||||
if (box.isEmpty())
|
|
||||||
return;
|
|
||||||
List<ItemStack> contents = CardboardBoxItem.getContents(box);
|
|
||||||
if (InsertAll(contents, true)) {
|
|
||||||
ItemStack copy = box.copy();
|
|
||||||
copy.shrink(1);
|
|
||||||
inventory.setStackInSlot(ShippingInventory.RECEIVING, copy);
|
|
||||||
InsertAll(contents, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean InsertAll(List<ItemStack> stacks, boolean simulate) {
|
|
||||||
removeInvalidatedInventories();
|
|
||||||
for (ItemStack stack : stacks) {
|
|
||||||
ItemStack toInsert = stack.copy();
|
|
||||||
|
|
||||||
InventoryScan: for (IItemHandler inv : getObservedInventories()) {
|
|
||||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
|
||||||
toInsert = inv.insertItem(slot, stack, simulate);
|
|
||||||
if (toInsert.isEmpty())
|
|
||||||
break InventoryScan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!toInsert.isEmpty())
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeInvalidatedInventories() {
|
|
||||||
observedInventories.keySet().stream().filter(key -> !observedInventories.get(key).itemHandler.isPresent())
|
|
||||||
.collect(Collectors.toList()).forEach(this::detachInventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initialize() {
|
|
||||||
super.initialize();
|
|
||||||
BlockPos start = pos.offset(getBlockState().get(FACING).getOpposite());
|
|
||||||
List<BlockPos> toUpdate = LogisticalControllerBlock.collectCasings(world, start);
|
|
||||||
for (BlockPos blockPos : toUpdate) {
|
|
||||||
world.updateComparatorOutputLevel(blockPos, world.getBlockState(blockPos).getBlock());
|
|
||||||
|
|
||||||
for (Direction face : Direction.values()) {
|
|
||||||
BlockPos neighbour = blockPos.offset(face);
|
|
||||||
BlockState invState = world.getBlockState(neighbour);
|
|
||||||
if (!invState.hasTileEntity())
|
|
||||||
continue;
|
|
||||||
TileEntity invTE = world.getTileEntity(neighbour);
|
|
||||||
if (invTE instanceof LogisticalCasingTileEntity)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
LazyOptional<IItemHandler> inventory = invTE
|
|
||||||
.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
|
|
||||||
if (!inventory.isPresent())
|
|
||||||
continue;
|
|
||||||
addInventory(neighbour, inventory);
|
|
||||||
taskCooldown = COOLDOWN;
|
|
||||||
checkTasks = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkTasks() {
|
|
||||||
for (Iterator<LogisticalTask> iterator = getNetwork().internalTaskQueue.iterator(); iterator.hasNext();) {
|
|
||||||
LogisticalTask task = iterator.next();
|
|
||||||
|
|
||||||
if (canSupply() && task instanceof SupplyTask) {
|
|
||||||
List<Pair<Ingredient, Integer>> items = ((SupplyTask) task).items;
|
|
||||||
if (findItems(items, true) == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
List<ItemStack> collectedStacks = findItems(items, false);
|
|
||||||
getInventory().createPackage(collectedStacks, task.targetAddress);
|
|
||||||
iterator.remove();
|
|
||||||
checkTasks = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canReceive() && task instanceof DepositTask) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ItemStack> findItems(List<Pair<Ingredient, Integer>> items, boolean simulate) {
|
|
||||||
removeInvalidatedInventories();
|
|
||||||
List<ItemStack> foundItems = new ArrayList<>();
|
|
||||||
|
|
||||||
// Over Requested Ingredients
|
|
||||||
for (Pair<Ingredient, Integer> pair : items) {
|
|
||||||
int amountLeft = pair.getValue();
|
|
||||||
|
|
||||||
// Over Attached inventories
|
|
||||||
InventoryScan: for (IItemHandler inv : getObservedInventories()) {
|
|
||||||
|
|
||||||
// Over Slots
|
|
||||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
|
||||||
ItemStack stackInSlot = inv.getStackInSlot(slot);
|
|
||||||
if (!pair.getKey().test(stackInSlot))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ItemStack extracted = inv.extractItem(slot, amountLeft, simulate);
|
|
||||||
amountLeft -= extracted.getCount();
|
|
||||||
ItemHelper.addToList(extracted, foundItems);
|
|
||||||
|
|
||||||
if (amountLeft == 0)
|
|
||||||
break InventoryScan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (amountLeft > 0)
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return foundItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CountedItemsList getAllItems() {
|
|
||||||
if (inventorySetDirty)
|
|
||||||
refreshItemHandlerSet();
|
|
||||||
return allItems.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<IItemHandler> getObservedInventories() {
|
|
||||||
if (inventorySetDirty)
|
|
||||||
refreshItemHandlerSet();
|
|
||||||
return inventoryByHandler.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refreshItemHandlerSet() {
|
|
||||||
inventorySetDirty = false;
|
|
||||||
inventoryByHandler.clear();
|
|
||||||
allItems.clear();
|
|
||||||
observedInventories.forEach((pos, connectedInventory) -> {
|
|
||||||
if (connectedInventory.itemHandler.isPresent()) {
|
|
||||||
IItemHandler inv = connectedInventory.itemHandler.orElse(null);
|
|
||||||
for (IItemHandler iItemHandler : inventoryByHandler.keySet()) {
|
|
||||||
if (ItemHelper.isSameInventory(iItemHandler, inv))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
inventoryByHandler.put(inv, connectedInventory);
|
|
||||||
allItems.add(inv, connectedInventory.countedItems);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundNBT write(CompoundNBT compound) {
|
|
||||||
shippingInventory.ifPresent(inv -> compound.put("ShippingInventory", ((ShippingInventory) inv).serializeNBT()));
|
|
||||||
compound.putBoolean("Active", isActive);
|
|
||||||
return super.write(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
shippingInventory.invalidate();
|
|
||||||
super.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> LazyOptional<T> getCasingCapability(Capability<T> cap, Direction side) {
|
|
||||||
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
|
|
||||||
return shippingInventory.cast();
|
|
||||||
return LazyOptional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean canSupply() {
|
|
||||||
return isSupplier() && getInventory().canCreatePackage();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean canReceive() {
|
|
||||||
return isReceiver();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ShippingInventory getInventory() {
|
|
||||||
return (ShippingInventory) shippingInventory.orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ConnectedInventory {
|
|
||||||
LazyOptional<IItemHandler> itemHandler;
|
|
||||||
CountedItemsList countedItems;
|
|
||||||
|
|
||||||
public ConnectedInventory(LazyOptional<IItemHandler> inv) {
|
|
||||||
itemHandler = inv;
|
|
||||||
countedItems = makeList(inv);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CountedItemsList makeList(LazyOptional<IItemHandler> inv) {
|
|
||||||
return inv.isPresent() ? new CountedItemsList(inv.orElse(null)) : new CountedItemsList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ItemStackEntry> refresh() {
|
|
||||||
CountedItemsList newList = makeList(itemHandler);
|
|
||||||
List<ItemStackEntry> stacksToUpdate = countedItems.getStacksToUpdate(newList);
|
|
||||||
countedItems = newList;
|
|
||||||
allItems.add(itemHandler.orElse(null), countedItems);
|
|
||||||
return stacksToUpdate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IContainerFactory<LogisticalInventoryControllerTileEntity, LogisticalInventoryControllerContainer> getContainerFactory() {
|
|
||||||
return LogisticalInventoryControllerContainer::new;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendToContainer(PacketBuffer buffer) {
|
|
||||||
IWithContainer.super.sendToContainer(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract ShippingInventory createInventory();
|
|
||||||
|
|
||||||
public class ShippingInventory extends ItemStackHandler {
|
|
||||||
|
|
||||||
public static final int SHIPPING = 0;
|
|
||||||
public static final int RECEIVING = 1;
|
|
||||||
public static final int FILTER = 2;
|
|
||||||
int filterAmount = 0;
|
|
||||||
|
|
||||||
boolean ships;
|
|
||||||
boolean receives;
|
|
||||||
|
|
||||||
public ShippingInventory(boolean ships, boolean receives) {
|
|
||||||
super(3);
|
|
||||||
this.ships = ships;
|
|
||||||
this.receives = receives;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemValid(int slot, ItemStack stack) {
|
|
||||||
if (slot == FILTER)
|
|
||||||
return true;
|
|
||||||
if (slot == RECEIVING && receives)
|
|
||||||
return stack.getItem() instanceof CardboardBoxItem && CardboardBoxItem.matchAddress(stack, address);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canCreatePackage() {
|
|
||||||
return getStackInSlot(SHIPPING).isEmpty() && ships;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
|
||||||
if (slot == RECEIVING)
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
return super.extractItem(slot, amount, simulate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setStackInSlot(int slot, ItemStack stack) {
|
|
||||||
if (slot == FILTER) {
|
|
||||||
stack = stack.copy();
|
|
||||||
stack.setCount(1);
|
|
||||||
}
|
|
||||||
super.setStackInSlot(slot, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createPackage(List<ItemStack> contents, String address) {
|
|
||||||
ItemStack box = CardboardBoxItem.containing(contents);
|
|
||||||
CardboardBoxItem.addAddress(box, address);
|
|
||||||
setStackInSlot(SHIPPING, box);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onContentsChanged(int slot) {
|
|
||||||
super.onContentsChanged(slot);
|
|
||||||
markDirty();
|
|
||||||
boolean empty = getStackInSlot(slot).isEmpty();
|
|
||||||
|
|
||||||
if (slot == RECEIVING && !empty)
|
|
||||||
tryInsertBox = true;
|
|
||||||
|
|
||||||
if (slot == RECEIVING && empty) {
|
|
||||||
if (getNetwork() != null) {
|
|
||||||
getNetwork().packageTargets.forEach(target -> {
|
|
||||||
if (target.getAddressList().stream()
|
|
||||||
.anyMatch(e -> LogisticalNetwork.matchAddresses(e, address)))
|
|
||||||
target.slotOpened();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slot == SHIPPING && empty)
|
|
||||||
checkTasks = true;
|
|
||||||
|
|
||||||
BlockPos start = pos.offset(getBlockState().get(FACING).getOpposite());
|
|
||||||
List<BlockPos> toUpdate = LogisticalControllerBlock.collectCasings(world, start);
|
|
||||||
for (BlockPos blockPos : toUpdate) {
|
|
||||||
TileEntity tileEntity = world.getTileEntity(blockPos);
|
|
||||||
if (tileEntity == null)
|
|
||||||
continue;
|
|
||||||
tileEntity.getWorld().updateComparatorOutputLevel(blockPos, tileEntity.getBlockState().getBlock());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundNBT serializeNBT() {
|
|
||||||
CompoundNBT tag = super.serializeNBT();
|
|
||||||
tag.putBoolean("Ships", ships);
|
|
||||||
tag.putBoolean("Receives", receives);
|
|
||||||
tag.putInt("FilterAmount", filterAmount);
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deserializeNBT(CompoundNBT nbt) {
|
|
||||||
ships = nbt.getBoolean("Ships");
|
|
||||||
receives = nbt.getBoolean("Receives");
|
|
||||||
filterAmount = nbt.getInt("FilterAmount");
|
|
||||||
super.deserializeNBT(nbt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
|
|
||||||
public class RequestTileEntity extends LogisticalInventoryControllerTileEntity {
|
|
||||||
|
|
||||||
public RequestTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICAL_REQUEST_CONTROLLER.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ShippingInventory createInventory() {
|
|
||||||
return new ShippingInventory(false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleAdded() {
|
|
||||||
if (world.isRemote)
|
|
||||||
return;
|
|
||||||
if (getNetwork() != null)
|
|
||||||
return;
|
|
||||||
super.handleAdded();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReceiver() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
|
|
||||||
public class StorageTileEntity extends LogisticalInventoryControllerTileEntity {
|
|
||||||
|
|
||||||
public StorageTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICAL_STORAGE_CONTROLLER.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ShippingInventory createInventory() {
|
|
||||||
return new ShippingInventory(true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSupplier() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReceiver() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
|
|
||||||
public class SupplyTileEntity extends LogisticalInventoryControllerTileEntity {
|
|
||||||
|
|
||||||
public SupplyTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICAL_SUPPLY_CONTROLLER.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ShippingInventory createInventory() {
|
|
||||||
return new ShippingInventory(true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSupplier() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.controller;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity;
|
|
||||||
|
|
||||||
public class TransactionsTileEntity extends LogisticalActorTileEntity {
|
|
||||||
|
|
||||||
public TransactionsTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICAL_TRANSATIONS_CONTROLLER.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.index;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.packet.SimplePacketBase;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.inventory.container.Container;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
|
||||||
|
|
||||||
public class IndexContainerUpdatePacket extends SimplePacketBase {
|
|
||||||
|
|
||||||
public enum Type {
|
|
||||||
INITIAL, UPDATE
|
|
||||||
}
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
List<Pair<String, CountedItemsList>> items;
|
|
||||||
BlockPos pos;
|
|
||||||
|
|
||||||
public IndexContainerUpdatePacket(Type type, String address, CountedItemsList items, BlockPos pos) {
|
|
||||||
this(type, Arrays.asList(Pair.of(address, items)), pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexContainerUpdatePacket(Type type, List<Pair<String, CountedItemsList>> items, BlockPos pos) {
|
|
||||||
this.type = type;
|
|
||||||
this.items = items;
|
|
||||||
this.pos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexContainerUpdatePacket(PacketBuffer buffer) {
|
|
||||||
type = Type.values()[buffer.readInt()];
|
|
||||||
int numControllers = buffer.readInt();
|
|
||||||
items = new ArrayList<>(numControllers);
|
|
||||||
for (int i = 0; i < numControllers; i++) {
|
|
||||||
String address = buffer.readString(4096);
|
|
||||||
CountedItemsList itemList = new CountedItemsList();
|
|
||||||
int numEntries = buffer.readInt();
|
|
||||||
for (int j = 0; j < numEntries; j++)
|
|
||||||
itemList.add(buffer.readItemStack(), buffer.readInt());
|
|
||||||
items.add(Pair.of(address, itemList));
|
|
||||||
}
|
|
||||||
pos = buffer.readBlockPos();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(PacketBuffer buffer) {
|
|
||||||
buffer.writeInt(type.ordinal());
|
|
||||||
buffer.writeInt(items.size());
|
|
||||||
for (Pair<String, CountedItemsList> pair : items) {
|
|
||||||
buffer.writeString(pair.getKey(), 4096);
|
|
||||||
Collection<ItemStackEntry> entries = pair.getValue().getFlattenedList();
|
|
||||||
buffer.writeInt(entries.size());
|
|
||||||
for (ItemStackEntry entry : entries) {
|
|
||||||
buffer.writeItemStack(entry.stack);
|
|
||||||
buffer.writeInt(entry.amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buffer.writeBlockPos(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(Supplier<Context> context) {
|
|
||||||
context.get().enqueueWork(() -> {
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
Container openContainer = mc.player.openContainer;
|
|
||||||
if (openContainer == null)
|
|
||||||
return;
|
|
||||||
if (!(openContainer instanceof LogisticalIndexContainer))
|
|
||||||
return;
|
|
||||||
LogisticalIndexTileEntity te = (LogisticalIndexTileEntity) mc.world.getTileEntity(pos);
|
|
||||||
if (te == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (type == Type.INITIAL)
|
|
||||||
te.index(items);
|
|
||||||
if (type == Type.UPDATE)
|
|
||||||
te.update(items);
|
|
||||||
|
|
||||||
((LogisticalIndexContainer) openContainer).refresh();
|
|
||||||
});
|
|
||||||
context.get().setPacketHandled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.index;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import com.simibubi.create.Create;
|
|
||||||
import com.simibubi.create.foundation.packet.SimplePacketBase;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
|
|
||||||
import com.simibubi.create.modules.logistics.management.LogisticalNetwork;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalTask.SupplyTask;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
|
||||||
|
|
||||||
public class IndexOrderRequest extends SimplePacketBase {
|
|
||||||
|
|
||||||
String targetAddress;
|
|
||||||
UUID networkID;
|
|
||||||
CountedItemsList items;
|
|
||||||
BlockPos indexPos;
|
|
||||||
|
|
||||||
public IndexOrderRequest(BlockPos indexPos, String targetAddress, CountedItemsList list, UUID networkID) {
|
|
||||||
this.targetAddress = targetAddress;
|
|
||||||
items = list;
|
|
||||||
this.networkID = networkID;
|
|
||||||
this.indexPos = indexPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexOrderRequest(PacketBuffer buffer) {
|
|
||||||
indexPos = buffer.readBlockPos();
|
|
||||||
networkID = new UUID(buffer.readLong(), buffer.readLong());
|
|
||||||
targetAddress = buffer.readString(4096);
|
|
||||||
items = new CountedItemsList();
|
|
||||||
int numEntries = buffer.readInt();
|
|
||||||
for (int j = 0; j < numEntries; j++)
|
|
||||||
items.add(buffer.readItemStack(), buffer.readInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(PacketBuffer buffer) {
|
|
||||||
buffer.writeBlockPos(indexPos);
|
|
||||||
buffer.writeLong(networkID.getMostSignificantBits());
|
|
||||||
buffer.writeLong(networkID.getLeastSignificantBits());
|
|
||||||
buffer.writeString(targetAddress, 4096);
|
|
||||||
Collection<ItemStackEntry> entries = items.getFlattenedList();
|
|
||||||
buffer.writeInt(entries.size());
|
|
||||||
for (ItemStackEntry entry : entries) {
|
|
||||||
buffer.writeItemStack(entry.stack);
|
|
||||||
buffer.writeInt(entry.amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(Supplier<Context> context) {
|
|
||||||
context.get().enqueueWork(() -> {
|
|
||||||
ServerPlayerEntity player = context.get().getSender();
|
|
||||||
TileEntity tileEntity = player.getEntityWorld().getTileEntity(indexPos);
|
|
||||||
if (tileEntity != null && tileEntity instanceof LogisticalIndexTileEntity)
|
|
||||||
((LogisticalIndexTileEntity) tileEntity).lastOrderAddress = targetAddress;
|
|
||||||
LogisticalNetwork networkByID = Create.logisticalNetworkHandler.getNetworkByID(player.getEntityWorld(),
|
|
||||||
networkID);
|
|
||||||
items.getFlattenedList().forEach(entry -> networkByID.enqueueTask(new SupplyTask(entry, targetAddress)));
|
|
||||||
});
|
|
||||||
context.get().setPacketHandled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,155 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.index;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllItems;
|
|
||||||
import com.simibubi.create.foundation.block.IHaveColorHandler;
|
|
||||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.block.HorizontalBlock;
|
|
||||||
import net.minecraft.client.renderer.color.IBlockColor;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
|
||||||
import net.minecraft.item.ItemGroup;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.BlockRenderLayer;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.NonNullList;
|
|
||||||
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.world.IBlockReader;
|
|
||||||
import net.minecraft.world.IWorldReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
|
||||||
|
|
||||||
public class LogisticalIndexBlock extends HorizontalBlock
|
|
||||||
implements IHaveColorHandler, IWithTileEntity<LogisticalIndexTileEntity> {
|
|
||||||
|
|
||||||
public LogisticalIndexBlock() {
|
|
||||||
super(Properties.from(Blocks.GRANITE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
|
||||||
Direction facing = state.get(HORIZONTAL_FACING);
|
|
||||||
BlockPos offset = pos.offset(facing.getOpposite());
|
|
||||||
BlockState blockState = worldIn.getBlockState(offset);
|
|
||||||
return !blockState.getMaterial().isReplaceable();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
|
||||||
builder.add(HORIZONTAL_FACING);
|
|
||||||
super.fillStateContainer(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
|
|
||||||
super.fillItemGroup(group, items);
|
|
||||||
AllItems[] logisiticalItems = new AllItems[] { AllItems.LOGISTICAL_DIAL, AllItems.LOGISTICAL_CONTROLLER_STORAGE,
|
|
||||||
AllItems.LOGISTICAL_CONTROLLER_SUPPLY, AllItems.LOGISTICAL_CONTROLLER_REQUEST,
|
|
||||||
AllItems.LOGISTICAL_CONTROLLER_CALCULATION, AllItems.LOGISTICAL_CONTROLLER_TRANSACTIONS };
|
|
||||||
for (AllItems item : logisiticalItems) {
|
|
||||||
item.get().fillItemGroup(group, items);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockRenderLayer getRenderLayer() {
|
|
||||||
return BlockRenderLayer.CUTOUT_MIPPED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
||||||
BlockState defaultState = getDefaultState();
|
|
||||||
if (context.getFace().getAxis().isHorizontal())
|
|
||||||
return defaultState.with(HORIZONTAL_FACING, context.getFace());
|
|
||||||
return defaultState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
|
||||||
boolean isMoving) {
|
|
||||||
if (state.isValidPosition(worldIn, pos))
|
|
||||||
return;
|
|
||||||
|
|
||||||
TileEntity tileentity = state.hasTileEntity() ? worldIn.getTileEntity(pos) : null;
|
|
||||||
spawnDrops(state, worldIn, pos, tileentity);
|
|
||||||
worldIn.removeBlock(pos, false);
|
|
||||||
|
|
||||||
for (Direction direction : Direction.values())
|
|
||||||
worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTileEntity(BlockState state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
|
||||||
return new LogisticalIndexTileEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
|
|
||||||
BlockRayTraceResult hit) {
|
|
||||||
if (AllItems.LOGISTICAL_DIAL.typeOf(player.getHeldItem(handIn))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (worldIn.isRemote) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
withTileEntityDo(worldIn, pos, te -> {
|
|
||||||
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
|
||||||
if (!(placer instanceof PlayerEntity))
|
|
||||||
return;
|
|
||||||
PlayerEntity player = (PlayerEntity) placer;
|
|
||||||
for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++) {
|
|
||||||
ItemStack itemStack = player.inventory.getStackInSlot(slot);
|
|
||||||
if (!AllItems.LOGISTICAL_DIAL.typeOf(itemStack))
|
|
||||||
continue;
|
|
||||||
if (!itemStack.hasTag())
|
|
||||||
continue;
|
|
||||||
withTileEntityDo(worldIn, pos, te -> te.setNetworkId(itemStack.getTag().getUniqueId("NetworkID")));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
||||||
return AllShapes.LOGISTICAL_INDEX.get(state.get(HORIZONTAL_FACING));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBlockColor getColorHandler() {
|
|
||||||
return (state, world, pos, layer) -> {
|
|
||||||
if (layer == 0) {
|
|
||||||
LogisticalIndexTileEntity tileEntity = getTileEntity(world, pos);
|
|
||||||
if (tileEntity == null)
|
|
||||||
return 0;
|
|
||||||
return tileEntity.getColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.index;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllContainers;
|
|
||||||
import com.simibubi.create.foundation.type.CombinedCountedItemsList;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.world.ClientWorld;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.inventory.container.Container;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
|
|
||||||
public class LogisticalIndexContainer extends Container {
|
|
||||||
|
|
||||||
public LogisticalIndexTileEntity te;
|
|
||||||
public CombinedCountedItemsList<String> allItems = new CombinedCountedItemsList<>();
|
|
||||||
|
|
||||||
public LogisticalIndexContainer(int id, PlayerInventory inv, PacketBuffer extraData) {
|
|
||||||
super(AllContainers.LOGISTICAL_INDEX.type, id);
|
|
||||||
ClientWorld world = Minecraft.getInstance().world;
|
|
||||||
this.te = (LogisticalIndexTileEntity) world.getTileEntity(extraData.readBlockPos());
|
|
||||||
this.te.handleUpdateTag(extraData.readCompoundTag());
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogisticalIndexContainer(int id, PlayerInventory inv, LogisticalIndexTileEntity te) {
|
|
||||||
super(AllContainers.LOGISTICAL_INDEX.type, id);
|
|
||||||
this.te = te;
|
|
||||||
init();
|
|
||||||
te.addPlayer((ServerPlayerEntity) inv.player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
detectAndSendChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onContainerClosed(PlayerEntity playerIn) {
|
|
||||||
if (!te.getWorld().isRemote)
|
|
||||||
te.removePlayer((ServerPlayerEntity) playerIn);
|
|
||||||
else
|
|
||||||
te.controllers.clear();
|
|
||||||
super.onContainerClosed(playerIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInteractWith(PlayerEntity playerIn) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh() {
|
|
||||||
allItems.clear();
|
|
||||||
te.controllers.forEach(allItems::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,569 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.index;
|
|
||||||
|
|
||||||
import static com.simibubi.create.ScreenResources.DISABLED_SLOT_FRAME;
|
|
||||||
import static com.simibubi.create.ScreenResources.DISABLED_SLOT_INNER;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_BOTTOM;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_BOTTOM_TRIM;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_MIDDLE;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_SCROLLER_BOTTOM;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_SCROLLER_MIDDLE;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_SCROLLER_TOP;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_SEARCH;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_SEARCH_OVERLAY;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_TAB;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_TAB_ACTIVE;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_TOP;
|
|
||||||
import static com.simibubi.create.ScreenResources.INDEX_TOP_TRIM;
|
|
||||||
import static com.simibubi.create.ScreenResources.I_CONFIRM;
|
|
||||||
import static com.simibubi.create.ScreenResources.SLOT_FRAME;
|
|
||||||
import static com.simibubi.create.ScreenResources.SLOT_INNER;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.simibubi.create.AllPackets;
|
|
||||||
import com.simibubi.create.ScreenResources;
|
|
||||||
import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen;
|
|
||||||
import com.simibubi.create.foundation.gui.ScreenElementRenderer;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.IconButton;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.ScrollInput;
|
|
||||||
import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
|
|
||||||
import com.simibubi.create.foundation.utility.ColorHelper;
|
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
|
||||||
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.client.GameSettings;
|
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
|
||||||
import net.minecraft.client.util.InputMappings;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
|
|
||||||
public class LogisticalIndexScreen extends AbstractSimiContainerScreen<LogisticalIndexContainer> {
|
|
||||||
|
|
||||||
protected LogisticalIndexContainer container;
|
|
||||||
protected IconButton orderButton;
|
|
||||||
|
|
||||||
boolean searchActive = false;
|
|
||||||
boolean searchHovered = false;
|
|
||||||
InterpolatedChasingValue searchButtonOffset;
|
|
||||||
TextFieldWidget searchTextField;
|
|
||||||
String searchKey = "";
|
|
||||||
|
|
||||||
TextFieldWidget receiverTextField;
|
|
||||||
ScrollInput receiverScrollInput;
|
|
||||||
List<String> receivers = new ArrayList<>();
|
|
||||||
|
|
||||||
int cursorPos = 0;
|
|
||||||
boolean cursorActive = false;
|
|
||||||
InterpolatedChasingValue cursorLight;
|
|
||||||
|
|
||||||
List<ItemStackEntry> displayedItems = new ArrayList<>();
|
|
||||||
CountedItemsList order = new CountedItemsList();
|
|
||||||
String initialTargetAddress;
|
|
||||||
|
|
||||||
String title = Lang.translate("gui.index.title");
|
|
||||||
String receiverScrollInputTitle = Lang.translate("gui.index.targetAddressSelect");
|
|
||||||
String orderButtonTooltip = Lang.translate("gui.index.confirmOrder");
|
|
||||||
String keyNumberInventories = "gui.index.numberIndexedInventories";
|
|
||||||
ItemStack chestIcon = new ItemStack(Blocks.CHEST);
|
|
||||||
|
|
||||||
public LogisticalIndexScreen(LogisticalIndexContainer container, PlayerInventory inv, ITextComponent title) {
|
|
||||||
super(container, inv, title);
|
|
||||||
this.container = container;
|
|
||||||
cursorLight = new InterpolatedChasingValue().withSpeed(.25f);
|
|
||||||
searchButtonOffset = new InterpolatedChasingValue().withSpeed(.5f);
|
|
||||||
receivers = container.te.availableReceivers;
|
|
||||||
initialTargetAddress = container.te.lastOrderAddress;
|
|
||||||
buildDisplayedItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
int height = INDEX_TOP.height + INDEX_TOP_TRIM.height + INDEX_MIDDLE.height + INDEX_BOTTOM_TRIM.height
|
|
||||||
+ INDEX_BOTTOM.height;
|
|
||||||
int width = INDEX_MIDDLE.width;
|
|
||||||
setWindowSize(width, height);
|
|
||||||
super.init();
|
|
||||||
widgets.clear();
|
|
||||||
|
|
||||||
searchTextField = new TextFieldWidget(font, guiLeft + 23, guiTop + 8, 128, 8, "");
|
|
||||||
searchTextField.setTextColor(0xFFFFFF);
|
|
||||||
searchTextField.setDisabledTextColour(-1);
|
|
||||||
searchTextField.setEnableBackgroundDrawing(false);
|
|
||||||
searchTextField.setMaxStringLength(256);
|
|
||||||
searchTextField.setResponder(this::onSearchKeyChanged);
|
|
||||||
searchTextField.setFocused2(false);
|
|
||||||
|
|
||||||
receiverTextField = new TextFieldWidget(font, guiLeft + 29, guiTop + 240, 116, 8, "");
|
|
||||||
receiverTextField.setTextColor(0xFFFFFF);
|
|
||||||
receiverTextField.setDisabledTextColour(-1);
|
|
||||||
receiverTextField.setEnableBackgroundDrawing(false);
|
|
||||||
receiverTextField.setMaxStringLength(256);
|
|
||||||
receiverTextField.setResponder(this::onReceiverTextChanged);
|
|
||||||
if (initialTargetAddress != null)
|
|
||||||
receiverTextField.setText(initialTargetAddress);
|
|
||||||
receiverTextField.setFocused2(false);
|
|
||||||
|
|
||||||
receiverScrollInput = new SelectionScrollInput(guiLeft + 24, guiTop + 235, 126, 18).forOptions(receivers)
|
|
||||||
.titled(receiverScrollInputTitle).calling(this::onReceiverScrollInputChanged);
|
|
||||||
|
|
||||||
orderButton = new IconButton(guiLeft + 152, guiTop + 235, I_CONFIRM);
|
|
||||||
orderButton.active = false;
|
|
||||||
orderButton.setToolTip(orderButtonTooltip);
|
|
||||||
|
|
||||||
widgets.add(receiverTextField);
|
|
||||||
widgets.add(receiverScrollInput);
|
|
||||||
widgets.add(orderButton);
|
|
||||||
|
|
||||||
if (searchActive)
|
|
||||||
widgets.add(searchTextField);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
|
|
||||||
float targetOffset = 0.75f;
|
|
||||||
if (searchTextField.isFocused())
|
|
||||||
targetOffset = 1.5f;
|
|
||||||
else if (searchHovered || searchActive)
|
|
||||||
targetOffset = 1f;
|
|
||||||
searchButtonOffset.target(targetOffset);
|
|
||||||
searchButtonOffset.tick();
|
|
||||||
|
|
||||||
if (cursorActive) {
|
|
||||||
cursorLight.target(1);
|
|
||||||
cursorLight.tick();
|
|
||||||
} else {
|
|
||||||
cursorLight.set(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!searchActive && searchTextField.isFocused())
|
|
||||||
searchTextField.changeFocus(false);
|
|
||||||
|
|
||||||
if (container.te.update) {
|
|
||||||
buildDisplayedItems();
|
|
||||||
((SelectionScrollInput) receiverScrollInput).forOptions(container.te.availableReceivers);
|
|
||||||
container.te.update = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSubmitButton() {
|
|
||||||
orderButton.active = canSubmit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canSubmit() {
|
|
||||||
return !order.getFlattenedList().isEmpty()
|
|
||||||
&& container.te.availableReceivers.contains(receiverTextField.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onSearchKeyChanged(String newSearch) {
|
|
||||||
if (searchKey.equals(newSearch))
|
|
||||||
return;
|
|
||||||
searchKey = new String(newSearch);
|
|
||||||
buildDisplayedItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendRequest() {
|
|
||||||
String address = receiverTextField.getText();
|
|
||||||
UUID id = container.te.getNetworkId();
|
|
||||||
AllPackets.channel.sendToServer(new IndexOrderRequest(container.te.getPos(), address, order, id));
|
|
||||||
order = new CountedItemsList();
|
|
||||||
updateSubmitButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onReceiverTextChanged(String newSearch) {
|
|
||||||
if (!receiverTextField.isFocused())
|
|
||||||
return;
|
|
||||||
receiverScrollInput.setState(0);
|
|
||||||
receivers = container.te.availableReceivers.stream()
|
|
||||||
.filter(str -> str.toLowerCase().startsWith(newSearch.toLowerCase())).collect(Collectors.toList());
|
|
||||||
((SelectionScrollInput) receiverScrollInput).forOptions(receivers);
|
|
||||||
receiverScrollInput.active = !receivers.isEmpty();
|
|
||||||
if (receivers.isEmpty() || newSearch.isEmpty())
|
|
||||||
receiverTextField.setSuggestion(null);
|
|
||||||
else
|
|
||||||
receiverTextField.setSuggestion(receivers.get(0).substring(newSearch.length()));
|
|
||||||
updateSubmitButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onReceiverScrollInputChanged(int index) {
|
|
||||||
if (receivers.isEmpty())
|
|
||||||
return;
|
|
||||||
String address = receivers.get(index);
|
|
||||||
receiverTextField.setResponder(null);
|
|
||||||
receiverTextField.setSuggestion(null);
|
|
||||||
receiverTextField.setText(address);
|
|
||||||
receiverTextField.setResponder(this::onReceiverTextChanged);
|
|
||||||
updateSubmitButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buildDisplayedItems() {
|
|
||||||
if (searchKey.isEmpty()) {
|
|
||||||
displayedItems = container.allItems.get().getFlattenedList().stream().collect(Collectors.toList());
|
|
||||||
} else {
|
|
||||||
displayedItems = container.allItems
|
|
||||||
.get().getFlattenedList().parallelStream().filter(entry -> entry.stack.getDisplayName()
|
|
||||||
.getUnformattedComponentText().toLowerCase().startsWith(searchKey.toLowerCase()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
if (cursorActive)
|
|
||||||
moveCursor(cursorPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(double x, double y, int button) {
|
|
||||||
if (searchHovered && button == 0) {
|
|
||||||
setSearchActive(!searchActive);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (orderButton.isHovered() && orderButton.active) {
|
|
||||||
sendRequest();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.mouseClicked(x, y, button);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(double xPos, double yPos) {
|
|
||||||
cursorActive = false;
|
|
||||||
super.mouseMoved(xPos, yPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSearchActive(boolean searchActive) {
|
|
||||||
this.searchActive = searchActive;
|
|
||||||
if (searchActive) {
|
|
||||||
cursorActive = false;
|
|
||||||
searchTextField.setSelectionPos(0);
|
|
||||||
searchTextField.changeFocus(true);
|
|
||||||
widgets.add(searchTextField);
|
|
||||||
} else {
|
|
||||||
widgets.remove(searchTextField);
|
|
||||||
onSearchKeyChanged("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) {
|
|
||||||
InputMappings.Input mouseKey = InputMappings.getInputByCode(code, p_keyPressed_2_);
|
|
||||||
boolean receiverFocused = receiverTextField.isFocused();
|
|
||||||
boolean searchFocused = searchTextField.isFocused();
|
|
||||||
boolean space = code == GLFW.GLFW_KEY_SPACE;
|
|
||||||
boolean enter = code == GLFW.GLFW_KEY_ENTER;
|
|
||||||
boolean writingText = receiverFocused || searchFocused;
|
|
||||||
boolean closingScreen = this.minecraft.gameSettings.keyBindInventory.isActiveAndMatches(mouseKey);
|
|
||||||
|
|
||||||
if (closingScreen && writingText) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canSubmit() && hasShiftDown() && enter) {
|
|
||||||
sendRequest();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enter && searchActive && searchFocused) {
|
|
||||||
searchTextField.changeFocus(false);
|
|
||||||
searchTextField.setCursorPositionEnd();
|
|
||||||
searchTextField.setSelectionPos(searchTextField.getCursorPosition());
|
|
||||||
|
|
||||||
cursorActive = true;
|
|
||||||
cursorPos = 0;
|
|
||||||
|
|
||||||
if (searchTextField.getText().isEmpty())
|
|
||||||
setSearchActive(false);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enter && !writingText && cursorActive) {
|
|
||||||
ItemStackEntry entry = displayedItems.get(cursorPos);
|
|
||||||
if (!order.contains(entry.stack)) {
|
|
||||||
if (order.getFlattenedList().size() > 4)
|
|
||||||
return true;
|
|
||||||
order.add(entry);
|
|
||||||
} else
|
|
||||||
order.remove(entry.stack);
|
|
||||||
updateSubmitButton();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (space && !writingText) {
|
|
||||||
setSearchActive(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean up = code == GLFW.GLFW_KEY_UP;
|
|
||||||
boolean left = code == GLFW.GLFW_KEY_LEFT;
|
|
||||||
boolean down = code == GLFW.GLFW_KEY_DOWN;
|
|
||||||
boolean right = code == GLFW.GLFW_KEY_RIGHT;
|
|
||||||
boolean tab = code == GLFW.GLFW_KEY_TAB;
|
|
||||||
|
|
||||||
if (!writingText && tab) {
|
|
||||||
receiverTextField.setCursorPositionEnd();
|
|
||||||
receiverTextField.setSelectionPos(0);
|
|
||||||
receiverTextField.changeFocus(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (receiverFocused) {
|
|
||||||
if (enter) {
|
|
||||||
receiverTextField.changeFocus(false);
|
|
||||||
}
|
|
||||||
if (tab) {
|
|
||||||
if (receivers.isEmpty())
|
|
||||||
return false;
|
|
||||||
receiverTextField.setText(receivers.get(0));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (up || down) {
|
|
||||||
receiverScrollInput.setState(receiverScrollInput.getState() + (up ? -1 : 1));
|
|
||||||
receiverScrollInput.onChanged();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!writingText) {
|
|
||||||
GameSettings keys = minecraft.gameSettings;
|
|
||||||
boolean w = keys.keyBindForward.getKey().getKeyCode() == code || up;
|
|
||||||
boolean a = keys.keyBindLeft.getKey().getKeyCode() == code || left;
|
|
||||||
boolean s = keys.keyBindBack.getKey().getKeyCode() == code || down;
|
|
||||||
boolean d = keys.keyBindRight.getKey().getKeyCode() == code || right;
|
|
||||||
boolean any = w || a || s || d;
|
|
||||||
|
|
||||||
if (any && !cursorActive) {
|
|
||||||
cursorActive = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (any) {
|
|
||||||
int offset = w ? -8 : a ? -1 : s ? 8 : d ? 1 : 0;
|
|
||||||
if (hasShiftDown()) {
|
|
||||||
offset *= 4;
|
|
||||||
if (a || d) {
|
|
||||||
int col = cursorPos % 8;
|
|
||||||
offset = MathHelper.clamp(offset, -col, 7 - col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
moveCursor(cursorPos + offset);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void moveCursor(int slot) {
|
|
||||||
int clamp = MathHelper.clamp(slot, 0, slotsVisible() - 1);
|
|
||||||
if (cursorPos != clamp)
|
|
||||||
cursorLight.set(0).set(0);
|
|
||||||
cursorPos = clamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int slotsVisible() {
|
|
||||||
return displayedItems.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWindow(int mouseX, int mouseY, float partialTicks) {
|
|
||||||
applyNetworkColor();
|
|
||||||
|
|
||||||
// Search bar
|
|
||||||
searchHovered = (mouseX > guiLeft - 25 && mouseX < guiLeft && mouseY > guiTop + 6 && mouseY < guiTop + 31);
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
GlStateManager.translatef(searchButtonOffset.get(partialTicks) * -14, 0, 0);
|
|
||||||
INDEX_SEARCH.draw(this, guiLeft - 5, guiTop + 8);
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
|
|
||||||
INDEX_MIDDLE.draw(this, guiLeft, guiTop + INDEX_TOP.height + 6);
|
|
||||||
renderScrollbar();
|
|
||||||
renderTabs();
|
|
||||||
resetColor();
|
|
||||||
renderSlots();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean charTyped(char character, int code) {
|
|
||||||
if (!searchActive && !receiverTextField.isFocused())
|
|
||||||
return false;
|
|
||||||
if (character == ' ' && (searchTextField.getText().isEmpty()
|
|
||||||
|| searchTextField.getSelectedText().equals(searchTextField.getText())))
|
|
||||||
return false;
|
|
||||||
return super.charTyped(character, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderWindowForeground(int mouseX, int mouseY, float partialTicks) {
|
|
||||||
resetColor();
|
|
||||||
INDEX_TOP_TRIM.draw(this, guiLeft, guiTop + INDEX_TOP.height);
|
|
||||||
INDEX_BOTTOM_TRIM.draw(this, guiLeft, guiTop + INDEX_TOP.height + INDEX_MIDDLE.height + 6);
|
|
||||||
applyNetworkColor();
|
|
||||||
INDEX_TOP.draw(this, guiLeft, guiTop);
|
|
||||||
INDEX_BOTTOM.draw(this, guiLeft, guiTop + INDEX_TOP.height + INDEX_MIDDLE.height + 12);
|
|
||||||
|
|
||||||
if (searchActive) {
|
|
||||||
INDEX_SEARCH_OVERLAY.draw(this, guiLeft - 1, guiTop + 2);
|
|
||||||
resetColor();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
resetColor();
|
|
||||||
int offset = (INDEX_TOP.width - font.getStringWidth(title)) / 2;
|
|
||||||
font.drawStringWithShadow(title, guiLeft + offset, guiTop + 8,
|
|
||||||
ColorHelper.mixColors(0xFFFFFF, container.te.getColor(), .25f));
|
|
||||||
}
|
|
||||||
|
|
||||||
orderButton.render(mouseX, mouseY, partialTicks);
|
|
||||||
if (searchActive)
|
|
||||||
searchTextField.render(mouseX, mouseY, partialTicks);
|
|
||||||
receiverTextField.render(mouseX, mouseY, partialTicks);
|
|
||||||
|
|
||||||
renderOrderedItems();
|
|
||||||
ScreenElementRenderer.render3DItem(() -> {
|
|
||||||
GlStateManager.translated(guiLeft + 6.5, guiTop + 235, 0);
|
|
||||||
return chestIcon;
|
|
||||||
});
|
|
||||||
|
|
||||||
super.renderWindowForeground(mouseX, mouseY, partialTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderOrderedItems() {
|
|
||||||
Collection<ItemStackEntry> flattenedList = order.getFlattenedList();
|
|
||||||
|
|
||||||
int slotX = guiLeft + (getXSize() - flattenedList.size() * 18) / 2;
|
|
||||||
int slotY = guiTop + 215;
|
|
||||||
|
|
||||||
for (ItemStackEntry entry : flattenedList) {
|
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
|
||||||
GlStateManager.enableDepthTest();
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
GlStateManager.translatef(0.0F, 0.0F, 32.0F);
|
|
||||||
this.blitOffset = 200;
|
|
||||||
this.itemRenderer.zLevel = 200.0F;
|
|
||||||
net.minecraft.client.gui.FontRenderer font = entry.stack.getItem().getFontRenderer(entry.stack);
|
|
||||||
if (font == null)
|
|
||||||
font = this.font;
|
|
||||||
this.itemRenderer.renderItemAndEffectIntoGUI(entry.stack, slotX, slotY);
|
|
||||||
this.renderItemOverlayIntoGUI(font, entry.stack, slotX, slotY,
|
|
||||||
entry.amount > 1 ? String.valueOf(entry.amount) : null, 0xFFFFFF);
|
|
||||||
this.blitOffset = 0;
|
|
||||||
this.itemRenderer.zLevel = 0.0F;
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
slotX += 18;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderSlots() {
|
|
||||||
int slot = 0;
|
|
||||||
for (ItemStackEntry entry : displayedItems) {
|
|
||||||
resetColor();
|
|
||||||
|
|
||||||
renderSlot(slot, entry.stack, entry.amount);
|
|
||||||
slot++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderSlot(int slot, ItemStack stack, int count) {
|
|
||||||
int slotX = getSlotX(slot);
|
|
||||||
int slotY = getSlotY(slot);
|
|
||||||
|
|
||||||
// boolean ordered = order.contains(stack);
|
|
||||||
boolean orderedFully = order.getItemCount(stack) == count;
|
|
||||||
RenderHelper.disableStandardItemLighting();
|
|
||||||
|
|
||||||
if (orderedFully) {
|
|
||||||
DISABLED_SLOT_FRAME.draw(this, slotX, slotY);
|
|
||||||
DISABLED_SLOT_INNER.draw(this, slotX, slotY);
|
|
||||||
} else {
|
|
||||||
SLOT_FRAME.draw(this, slotX, slotY);
|
|
||||||
SLOT_INNER.draw(this, slotX, slotY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cursorActive && slot == cursorPos) {
|
|
||||||
renderCursor();
|
|
||||||
}
|
|
||||||
|
|
||||||
slotX++;
|
|
||||||
slotY++;
|
|
||||||
|
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
GlStateManager.translatef(0.0F, 0.0F, 32.0F);
|
|
||||||
this.blitOffset = 200;
|
|
||||||
this.itemRenderer.zLevel = 200.0F;
|
|
||||||
net.minecraft.client.gui.FontRenderer font = stack.getItem().getFontRenderer(stack);
|
|
||||||
if (font == null)
|
|
||||||
font = this.font;
|
|
||||||
this.itemRenderer.renderItemAndEffectIntoGUI(stack, slotX, slotY);
|
|
||||||
|
|
||||||
String text = count > 1 ? String.valueOf(count) : null;
|
|
||||||
int color = 0xFFFFFF;
|
|
||||||
if (orderedFully) {
|
|
||||||
color = ColorHelper.mixColors(container.te.getColor(), 0xFFFFFF, 0.5f);
|
|
||||||
text = new StringTextComponent("\u2714").getFormattedText();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.renderItemOverlayIntoGUI(font, stack, slotX, slotY, text, color);
|
|
||||||
this.blitOffset = 0;
|
|
||||||
this.itemRenderer.zLevel = 0.0F;
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSlotY(int slot) {
|
|
||||||
return guiTop + 28 + 18 * (slot / 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSlotX(int slot) {
|
|
||||||
return guiLeft + 15 + 18 * (slot % 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderScrollbar() {
|
|
||||||
INDEX_SCROLLER_TOP.draw(this, guiLeft + 173, guiTop + 31);
|
|
||||||
INDEX_SCROLLER_MIDDLE.draw(this, guiLeft + 173, guiTop + 37);
|
|
||||||
INDEX_SCROLLER_BOTTOM.draw(this, guiLeft + 173, guiTop + 43);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderTabs() {
|
|
||||||
INDEX_TAB.draw(this, guiLeft - 19, guiTop + 40);
|
|
||||||
INDEX_TAB_ACTIVE.draw(this, guiLeft - 19, guiTop + 61);
|
|
||||||
INDEX_TAB.draw(this, guiLeft - 19, guiTop + 82);
|
|
||||||
INDEX_TAB.draw(this, guiLeft - 19, guiTop + 103);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resetColor() {
|
|
||||||
ColorHelper.glResetColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void applyNetworkColor() {
|
|
||||||
ColorHelper.glColor(container.te.getColor());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderCursor() {
|
|
||||||
if (!cursorActive)
|
|
||||||
return;
|
|
||||||
int x = getSlotX(cursorPos);
|
|
||||||
int y = getSlotY(cursorPos);
|
|
||||||
|
|
||||||
float pt = minecraft.getRenderPartialTicks();
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.color4f(1, 1, 1, cursorLight.get(pt));
|
|
||||||
ScreenResources.SELECTED_SLOT_INNER.draw(this, x, y);
|
|
||||||
resetColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,208 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.management.index;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllPackets;
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList;
|
|
||||||
import com.simibubi.create.foundation.type.CountedItemsList.ItemStackEntry;
|
|
||||||
import com.simibubi.create.modules.logistics.management.LogisticalNetwork;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.index.IndexContainerUpdatePacket.Type;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
|
||||||
import net.minecraft.inventory.container.Container;
|
|
||||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.nbt.INBT;
|
|
||||||
import net.minecraft.nbt.ListNBT;
|
|
||||||
import net.minecraft.nbt.StringNBT;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraftforge.common.util.Constants.NBT;
|
|
||||||
import net.minecraftforge.fml.network.PacketDistributor;
|
|
||||||
|
|
||||||
public class LogisticalIndexTileEntity extends LogisticalActorTileEntity implements INamedContainerProvider {
|
|
||||||
|
|
||||||
// Server
|
|
||||||
public int nextPush;
|
|
||||||
public Set<ServerPlayerEntity> playersEntered = new HashSet<>();
|
|
||||||
protected Set<ServerPlayerEntity> playersUsing = new HashSet<>();
|
|
||||||
protected List<Pair<String, CountedItemsList>> controllersToUpdate = new LinkedList<>();
|
|
||||||
|
|
||||||
// Both
|
|
||||||
public String lastOrderAddress = null;
|
|
||||||
protected Map<String, CountedItemsList> controllers = new HashMap<>();
|
|
||||||
|
|
||||||
// Client
|
|
||||||
public boolean update = false;
|
|
||||||
public List<String> availableReceivers = new ArrayList<>();
|
|
||||||
|
|
||||||
public LogisticalIndexTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICAL_INDEX.type);
|
|
||||||
nextPush = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundNBT write(CompoundNBT compound) {
|
|
||||||
if (lastOrderAddress != null)
|
|
||||||
compound.putString("LastAdress", lastOrderAddress);
|
|
||||||
return super.write(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(CompoundNBT compound) {
|
|
||||||
if (compound.contains("LastAdress"))
|
|
||||||
lastOrderAddress = compound.getString("LastAdress");
|
|
||||||
super.read(compound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompoundNBT writeToClient(CompoundNBT tag) {
|
|
||||||
ListNBT receivers = new ListNBT();
|
|
||||||
availableReceivers.forEach(s -> receivers.add(new StringNBT(s)));
|
|
||||||
tag.put("Receivers", receivers);
|
|
||||||
return super.writeToClient(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readClientUpdate(CompoundNBT tag) {
|
|
||||||
availableReceivers.clear();
|
|
||||||
for (INBT inbt : tag.getList("Receivers", NBT.TAG_STRING))
|
|
||||||
availableReceivers.add(((StringNBT) inbt).getString());
|
|
||||||
update = true;
|
|
||||||
super.readClientUpdate(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void syncReceivers() {
|
|
||||||
if (network == null)
|
|
||||||
return;
|
|
||||||
availableReceivers.clear();
|
|
||||||
for (LogisticalActorTileEntity logisticalControllerTileEntity : network.receivers)
|
|
||||||
availableReceivers.add(logisticalControllerTileEntity.address);
|
|
||||||
sendData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initialize() {
|
|
||||||
super.initialize();
|
|
||||||
syncReceivers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
|
|
||||||
if (nextPush == 1)
|
|
||||||
pushItems();
|
|
||||||
|
|
||||||
if (nextPush > 0)
|
|
||||||
nextPush--;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Container createMenu(int id, PlayerInventory inv, PlayerEntity player) {
|
|
||||||
return new LogisticalIndexContainer(id, inv, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ITextComponent getDisplayName() {
|
|
||||||
return new StringTextComponent(getType().getRegistryName().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendToContainer(PacketBuffer buffer) {
|
|
||||||
buffer.writeBlockPos(getPos());
|
|
||||||
buffer.writeCompoundTag(getUpdateTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPlayer(ServerPlayerEntity player) {
|
|
||||||
nextPush = 5;
|
|
||||||
playersEntered.add(player);
|
|
||||||
playersUsing.add(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removePlayer(ServerPlayerEntity player) {
|
|
||||||
playersUsing.remove(player);
|
|
||||||
if (playersUsing.isEmpty())
|
|
||||||
controllers.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleUpdatedController(String address, CountedItemsList updates) {
|
|
||||||
if (playersUsing.isEmpty())
|
|
||||||
return;
|
|
||||||
controllersToUpdate.add(Pair.of(address, updates));
|
|
||||||
if (nextPush == 0)
|
|
||||||
nextPush = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pushItems() {
|
|
||||||
LogisticalNetwork network = this.getNetwork();
|
|
||||||
if (network == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// First player to open
|
|
||||||
if (!playersEntered.isEmpty() && playersUsing.size() == playersEntered.size()) {
|
|
||||||
controllers.clear();
|
|
||||||
for (LogisticalActorTileEntity te : network.suppliers) {
|
|
||||||
if (!(te instanceof LogisticalInventoryControllerTileEntity))
|
|
||||||
continue;
|
|
||||||
CountedItemsList allItems = ((LogisticalInventoryControllerTileEntity) te).getAllItems();
|
|
||||||
controllers.put(te.address, allItems);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initial Packets
|
|
||||||
if (!playersEntered.isEmpty()) {
|
|
||||||
controllers.forEach((address, items) -> {
|
|
||||||
for (ServerPlayerEntity player : playersUsing)
|
|
||||||
AllPackets.channel.send(PacketDistributor.PLAYER.with(() -> player),
|
|
||||||
new IndexContainerUpdatePacket(Type.INITIAL, address, items, pos));
|
|
||||||
});
|
|
||||||
playersEntered.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// pending Incremental Updates
|
|
||||||
if (!playersUsing.isEmpty() && !controllersToUpdate.isEmpty()) {
|
|
||||||
for (Pair<String, CountedItemsList> pair : controllersToUpdate) {
|
|
||||||
CountedItemsList list = controllers.getOrDefault(pair.getKey(), new CountedItemsList());
|
|
||||||
pair.getValue().getFlattenedList().forEach(list::add);
|
|
||||||
}
|
|
||||||
for (ServerPlayerEntity player : playersUsing)
|
|
||||||
AllPackets.channel.send(PacketDistributor.PLAYER.with(() -> player),
|
|
||||||
new IndexContainerUpdatePacket(Type.UPDATE, controllersToUpdate, pos));
|
|
||||||
controllersToUpdate.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void index(List<Pair<String, CountedItemsList>> items) {
|
|
||||||
items.forEach(pair -> {
|
|
||||||
controllers.put(pair.getKey(), pair.getValue());
|
|
||||||
});
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(List<Pair<String, CountedItemsList>> items) {
|
|
||||||
for (Pair<String, CountedItemsList> pair : items) {
|
|
||||||
if (!controllers.containsKey(pair.getKey()))
|
|
||||||
return;
|
|
||||||
CountedItemsList list = controllers.get(pair.getKey());
|
|
||||||
for (ItemStackEntry entry : pair.getValue().getFlattenedList()) {
|
|
||||||
list.setItemCount(entry.stack, entry.amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,434 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllEntities;
|
|
||||||
import com.simibubi.create.AllItems;
|
|
||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
|
||||||
import com.simibubi.create.modules.contraptions.components.actors.DrillTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.item.CardboardBoxItem;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EntitySize;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.Pose;
|
|
||||||
import net.minecraft.entity.SharedMonsterAttributes;
|
|
||||||
import net.minecraft.entity.item.ItemEntity;
|
|
||||||
import net.minecraft.entity.item.minecart.MinecartEntity;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.entity.projectile.AbstractArrowEntity;
|
|
||||||
import net.minecraft.inventory.EquipmentSlotType;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.network.IPacket;
|
|
||||||
import net.minecraft.network.PacketBuffer;
|
|
||||||
import net.minecraft.particles.ItemParticleData;
|
|
||||||
import net.minecraft.particles.ParticleTypes;
|
|
||||||
import net.minecraft.util.ActionResultType;
|
|
||||||
import net.minecraft.util.DamageSource;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.Direction.Axis;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.HandSide;
|
|
||||||
import net.minecraft.util.SoundEvent;
|
|
||||||
import net.minecraft.util.SoundEvents;
|
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
|
|
||||||
import net.minecraftforge.fml.network.FMLPlayMessages.SpawnEntity;
|
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
|
||||||
|
|
||||||
public class CardboardBoxEntity extends LivingEntity implements IEntityAdditionalSpawnData {
|
|
||||||
|
|
||||||
public ItemStack box;
|
|
||||||
|
|
||||||
public int extractorAnimationProgress;
|
|
||||||
public Direction extractorSide;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public CardboardBoxEntity(EntityType<? extends Entity> entityTypeIn, World worldIn) {
|
|
||||||
super((EntityType<? extends LivingEntity>) entityTypeIn, worldIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CardboardBoxEntity(World worldIn, double x, double y, double z) {
|
|
||||||
this(AllEntities.CARDBOARD_BOX.type, worldIn);
|
|
||||||
this.setPosition(x, y, z);
|
|
||||||
this.recalculateSize();
|
|
||||||
this.rotationYaw = this.rand.nextFloat() * 360.0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CardboardBoxEntity(World worldIn, Vec3d pos, ItemStack stack, Direction extractionDirection) {
|
|
||||||
this(worldIn, pos.x, pos.y, pos.z);
|
|
||||||
this.setBox(stack);
|
|
||||||
this.extractedFrom(extractionDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityType.Builder<?> build(EntityType.Builder<?> builder) {
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
EntityType.Builder<CardboardBoxEntity> boxBuilder = (EntityType.Builder<CardboardBoxEntity>) builder;
|
|
||||||
return boxBuilder.setCustomClientFactory(CardboardBoxEntity::spawn).size(1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void registerAttributes() {
|
|
||||||
super.registerAttributes();
|
|
||||||
this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(5.0D);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void extractedFrom(Direction side) {
|
|
||||||
extractorSide = side;
|
|
||||||
extractorAnimationProgress = 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAddress() {
|
|
||||||
return box.getTag().getString("Address");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
if (extractorAnimationProgress == 0) {
|
|
||||||
setMotion(new Vec3d(extractorSide.getDirectionVec()).scale(1 / 16f).add(0, 1 / 32f, 0));
|
|
||||||
}
|
|
||||||
if (extractorAnimationProgress > -1) {
|
|
||||||
extractorAnimationProgress--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntitySize getSize(Pose poseIn) {
|
|
||||||
if (box == null)
|
|
||||||
return super.getSize(poseIn);
|
|
||||||
if (AllItems.CARDBOARD_BOX_1410.typeOf(box))
|
|
||||||
return new EntitySize(14 / 16f, 10 / 16f, true);
|
|
||||||
if (AllItems.CARDBOARD_BOX_1416.typeOf(box))
|
|
||||||
return new EntitySize(14 / 16f, 1f, true);
|
|
||||||
if (AllItems.CARDBOARD_BOX_1612.typeOf(box))
|
|
||||||
return new EntitySize(1f, 12 / 16f, true);
|
|
||||||
if (AllItems.CARDBOARD_BOX_1616.typeOf(box))
|
|
||||||
return new EntitySize(1f, 1f, true);
|
|
||||||
|
|
||||||
return super.getSize(poseIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CardboardBoxEntity spawn(SpawnEntity spawnEntity, World world) {
|
|
||||||
return new CardboardBoxEntity(world, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getBox() {
|
|
||||||
return box;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBox(ItemStack box) {
|
|
||||||
this.box = box.copy();
|
|
||||||
recalculateSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AxisAlignedBB getCollisionBoundingBox() {
|
|
||||||
return getBoundingBox(getPose()).grow(-.1f, 0, -.1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBePushed() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AxisAlignedBB getCollisionBox(Entity entityIn) {
|
|
||||||
if (entityIn instanceof CardboardBoxEntity)
|
|
||||||
return getBoundingBox();
|
|
||||||
if (entityIn instanceof MinecartEntity)
|
|
||||||
return null;
|
|
||||||
return super.getCollisionBox(entityIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeCollidedWith() {
|
|
||||||
return isAlive();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyEntityCollision(Entity entityIn) {
|
|
||||||
if (entityIn instanceof CardboardBoxEntity) {
|
|
||||||
if (entityIn.getBoundingBox().minY < this.getBoundingBox().maxY) {
|
|
||||||
super.applyEntityCollision(entityIn);
|
|
||||||
}
|
|
||||||
} else if (entityIn.getBoundingBox().minY <= this.getBoundingBox().minY) {
|
|
||||||
super.applyEntityCollision(entityIn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ActionResultType applyPlayerInteraction(PlayerEntity player, Vec3d vec, Hand hand) {
|
|
||||||
return super.applyPlayerInteraction(player, vec, hand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean processInitialInteract(PlayerEntity player, Hand hand) {
|
|
||||||
if (player.getPassengers().isEmpty()) {
|
|
||||||
startRiding(player);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
for (Entity e : player.getPassengers()) {
|
|
||||||
while (e instanceof CardboardBoxEntity) {
|
|
||||||
if (e == this)
|
|
||||||
return false;
|
|
||||||
if (e.getPassengers().isEmpty()) {
|
|
||||||
startRiding(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
e = e.getPassengers().get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.processInitialInteract(player, hand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateRidden() {
|
|
||||||
super.updateRidden();
|
|
||||||
Entity ridingEntity = getRidingEntity();
|
|
||||||
if (ridingEntity instanceof LivingEntity) {
|
|
||||||
|
|
||||||
if (!(ridingEntity instanceof CardboardBoxEntity)) {
|
|
||||||
Vec3d front = VecHelper.rotate(new Vec3d(1, 0, 0), -90 - ridingEntity.getRotationYawHead(), Axis.Y);
|
|
||||||
double x = ridingEntity.posX + front.x;
|
|
||||||
double y = ridingEntity.posY + ridingEntity.getMountedYOffset() / 2 + this.getYOffset();
|
|
||||||
double z = ridingEntity.posZ + front.z;
|
|
||||||
|
|
||||||
prevRotationYaw = rotationYaw;
|
|
||||||
setRotation(-ridingEntity.rotationYaw, 0);
|
|
||||||
|
|
||||||
if (world.isRemote)
|
|
||||||
setPosition(x, y, z);
|
|
||||||
setPositionAndUpdate(x, y, z);
|
|
||||||
|
|
||||||
if (ridingEntity.isSneaking()) {
|
|
||||||
stopRiding();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
prevRotationYaw = rotationYaw;
|
|
||||||
setRotation(rotationYaw + ridingEntity.rotationYaw - ridingEntity.prevRotationYaw, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMountedYOffset() {
|
|
||||||
return this.getSize(getPose()).height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dismountEntity(Entity ridingEntity) {
|
|
||||||
boolean ridingBox = ridingEntity instanceof CardboardBoxEntity;
|
|
||||||
|
|
||||||
if (ridingBox) {
|
|
||||||
super.dismountEntity(ridingEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ridingEntity instanceof LivingEntity && !ridingBox) {
|
|
||||||
Vec3d front = VecHelper.rotate(new Vec3d(1, 0, 0), -90 - ridingEntity.rotationYaw, Axis.Y);
|
|
||||||
double x = ridingEntity.posX + front.x;
|
|
||||||
double y = ridingEntity.posY + ridingEntity.getMountedYOffset() / 2 + this.getYOffset();
|
|
||||||
double z = ridingEntity.posZ + front.z;
|
|
||||||
setRotation(-ridingEntity.rotationYaw, 0);
|
|
||||||
if (world.isRemote)
|
|
||||||
setPosition(x, y, z);
|
|
||||||
setPositionAndUpdate(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
getPassengers().forEach(x -> x.stopRiding());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onInsideBlock(BlockState state) {
|
|
||||||
if (state.getBlock() == Blocks.WATER) {
|
|
||||||
destroy(DamageSource.DROWN);
|
|
||||||
remove();
|
|
||||||
}
|
|
||||||
super.onInsideBlock(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean attackEntityFrom(DamageSource source, float amount) {
|
|
||||||
if (world.isRemote || !this.isAlive())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (DamageSource.OUT_OF_WORLD.equals(source)) {
|
|
||||||
this.remove();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DamageSource.IN_WALL.equals(source) && isPassenger())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (DamageSource.FALL.equals(source))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (this.isInvulnerableTo(source))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (source.isExplosion()) {
|
|
||||||
this.destroy(source);
|
|
||||||
this.remove();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DamageSource.IN_FIRE.equals(source)) {
|
|
||||||
if (this.isBurning()) {
|
|
||||||
this.takeDamage(source, 0.15F);
|
|
||||||
} else {
|
|
||||||
this.setFire(5);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DamageSource.ON_FIRE.equals(source) && this.getHealth() > 0.5F) {
|
|
||||||
this.takeDamage(source, 4.0F);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean wasShot = source.getImmediateSource() instanceof AbstractArrowEntity;
|
|
||||||
boolean shotCanPierce = wasShot && ((AbstractArrowEntity) source.getImmediateSource()).getPierceLevel() > 0;
|
|
||||||
|
|
||||||
if (source.getTrueSource() instanceof PlayerEntity
|
|
||||||
&& !((PlayerEntity) source.getTrueSource()).abilities.allowEdit)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this.destroy(source);
|
|
||||||
this.remove();
|
|
||||||
return shotCanPierce;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void takeDamage(DamageSource source, float amount) {
|
|
||||||
float hp = this.getHealth();
|
|
||||||
hp = hp - amount;
|
|
||||||
if (hp <= 0.5F) {
|
|
||||||
this.destroy(source);
|
|
||||||
this.remove();
|
|
||||||
} else {
|
|
||||||
this.setHealth(hp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void destroy(DamageSource source) {
|
|
||||||
this.world.playSound((PlayerEntity) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_ARMOR_STAND_BREAK,
|
|
||||||
this.getSoundCategory(), 1.0F, 1.0F);
|
|
||||||
this.spawnDrops(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void spawnDrops(DamageSource source) {
|
|
||||||
super.spawnDrops(source);
|
|
||||||
for (ItemStack stack : CardboardBoxItem.getContents(box)) {
|
|
||||||
ItemEntity entityIn = new ItemEntity(world, posX, posY, posZ, stack);
|
|
||||||
world.addEntity(entityIn);
|
|
||||||
if (DrillTileEntity.damageSourceDrill.equals(source))
|
|
||||||
entityIn.setMotion(Vec3d.ZERO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(boolean keepData) {
|
|
||||||
if (world.isRemote) {
|
|
||||||
for (int i = 0; i < 20; i++) {
|
|
||||||
Vec3d pos = VecHelper.offsetRandomly(this.getPositionVector(), world.rand, .5f);
|
|
||||||
Vec3d motion = Vec3d.ZERO;
|
|
||||||
world.addParticle(new ItemParticleData(ParticleTypes.ITEM, box), pos.x, pos.y, pos.z, motion.x,
|
|
||||||
motion.y, motion.z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.remove(keepData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void registerData() {
|
|
||||||
super.registerData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readAdditional(CompoundNBT compound) {
|
|
||||||
super.readAdditional(compound);
|
|
||||||
box = ItemStack.read(compound.getCompound("Box"));
|
|
||||||
if (compound.contains("Direction"))
|
|
||||||
extractedFrom(Direction.byIndex(compound.getInt("Direction")));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeAdditional(CompoundNBT compound) {
|
|
||||||
super.writeAdditional(compound);
|
|
||||||
compound.put("Box", box.serializeNBT());
|
|
||||||
if (extractorSide != null)
|
|
||||||
compound.putInt("Direction", extractorSide.getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IPacket<?> createSpawnPacket() {
|
|
||||||
return NetworkHooks.getEntitySpawningPacket(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<ItemStack> getArmorInventoryList() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItemStackFromSlot(EquipmentSlotType slotIn) {
|
|
||||||
if (slotIn == EquipmentSlotType.MAINHAND)
|
|
||||||
return getBox();
|
|
||||||
return ItemStack.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setItemStackToSlot(EquipmentSlotType slotIn, ItemStack stack) {
|
|
||||||
if (slotIn == EquipmentSlotType.MAINHAND)
|
|
||||||
setBox(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandSide getPrimaryHand() {
|
|
||||||
return HandSide.LEFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeSpawnData(PacketBuffer buffer) {
|
|
||||||
buffer.writeItemStack(getBox());
|
|
||||||
boolean sidePresent = extractorSide != null;
|
|
||||||
buffer.writeBoolean(sidePresent);
|
|
||||||
if (sidePresent)
|
|
||||||
buffer.writeInt(extractorSide.getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readSpawnData(PacketBuffer additionalData) {
|
|
||||||
setBox(additionalData.readItemStack());
|
|
||||||
if (additionalData.readBoolean())
|
|
||||||
extractedFrom(Direction.byIndex(additionalData.readInt()));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected SoundEvent getFallSound(int heightIn) {
|
|
||||||
return SoundEvents.ENTITY_ARMOR_STAND_FALL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
|
|
||||||
return SoundEvents.ENTITY_ARMOR_STAND_HIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
protected SoundEvent getDeathSound() {
|
|
||||||
return SoundEvents.ENTITY_ARMOR_STAND_BREAK;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
import net.minecraft.util.math.Vec3i;
|
|
||||||
|
|
||||||
public class CardboardBoxEntityRenderer extends EntityRenderer<CardboardBoxEntity> {
|
|
||||||
|
|
||||||
public CardboardBoxEntityRenderer(EntityRendererManager renderManager) {
|
|
||||||
super(renderManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ResourceLocation getEntityTexture(CardboardBoxEntity entity) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doRender(CardboardBoxEntity entity, double x, double y, double z, float entityYaw, float partialTicks) {
|
|
||||||
IBakedModel model = getModelForBox(entity);
|
|
||||||
if (model == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
GlStateManager.translated(x, y, z);
|
|
||||||
|
|
||||||
if (entity.extractorSide != null && entity.extractorAnimationProgress > 0) {
|
|
||||||
float offset = 0;
|
|
||||||
float yOffset = 0.55f;
|
|
||||||
float time = entity.extractorAnimationProgress - partialTicks;
|
|
||||||
float scale = 1;
|
|
||||||
if (time > 5) {
|
|
||||||
float step = (time - 10) / 10;
|
|
||||||
offset = MathHelper.lerp(step, -.5f, -1.5f);
|
|
||||||
scale = MathHelper.lerp(step, .3f, .3f);
|
|
||||||
} else {
|
|
||||||
float step = time / 5;
|
|
||||||
float cubicStep = step * step * step;
|
|
||||||
offset = -cubicStep * .5f;
|
|
||||||
yOffset = step * .55f;
|
|
||||||
scale = MathHelper.lerp(cubicStep, 1, .3f);
|
|
||||||
}
|
|
||||||
|
|
||||||
GlStateManager.scaled(scale, scale, scale);
|
|
||||||
Vec3i vec = entity.extractorSide.getDirectionVec();
|
|
||||||
GlStateManager.translated(offset * vec.getX(), offset * vec.getY() + yOffset, offset * vec.getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
GlStateManager.rotated(entity.rotationYaw, 0, 1, 0);
|
|
||||||
GlStateManager.translated(-.5, 0, .5);
|
|
||||||
|
|
||||||
Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightness(model,
|
|
||||||
Blocks.AIR.getDefaultState(), 1, false);
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
|
|
||||||
super.doRender(entity, x, y, z, entityYaw, partialTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IBakedModel getModelForBox(CardboardBoxEntity entity) {
|
|
||||||
if (entity.getBox() == null || entity.getBox().isEmpty())
|
|
||||||
return null;
|
|
||||||
return Minecraft.getInstance().getItemRenderer().getModelWithOverrides(entity.getBox());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleStatus;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.entity.ai.brain.task.Task;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class CollectPackageTask extends Task<VillagerEntity> {
|
|
||||||
private List<CardboardBoxEntity> foundPackages = new ArrayList<>();
|
|
||||||
|
|
||||||
public CollectPackageTask() {
|
|
||||||
super(ImmutableMap.of(MemoryModuleType.LOOK_TARGET, MemoryModuleStatus.VALUE_ABSENT,
|
|
||||||
MemoryModuleType.WALK_TARGET, MemoryModuleStatus.VALUE_ABSENT), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
this.foundPackages = worldIn.getEntitiesWithinAABB(CardboardBoxEntity.class,
|
|
||||||
owner.getBoundingBox().grow(1.0D, 0.5D, 1.0D),
|
|
||||||
e -> !e.isPassenger() && !e.getPersistentData().getBoolean("Delivered"));
|
|
||||||
return !this.foundPackages.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
LogisticianHandler.ponder(entityIn, "Yoink!");
|
|
||||||
CardboardBoxEntity box = this.foundPackages.get(worldIn.rand.nextInt(this.foundPackages.size()));
|
|
||||||
Entity e = entityIn;
|
|
||||||
while (!e.getPassengers().isEmpty())
|
|
||||||
e = e.getPassengers().get(0);
|
|
||||||
box.startRiding(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.WalkTarget;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.BlockPosWrapper;
|
|
||||||
import net.minecraft.util.math.GlobalPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class DeliverPackageToDestinationTask extends PackageDeliveryTask {
|
|
||||||
|
|
||||||
private GlobalPos rememberedAddress;
|
|
||||||
|
|
||||||
public DeliverPackageToDestinationTask() {
|
|
||||||
super(60);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
if (!super.shouldExecute(worldIn, owner))
|
|
||||||
return false;
|
|
||||||
rememberedAddress = LogisticianHandler.getRememberedAddress(owner, getBox(owner).getAddress());
|
|
||||||
return rememberedAddress != null && !rememberedAddress.getPos().withinDistance(owner.getPosition(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
LogisticianHandler.ponder(entityIn, "I know where this is!");
|
|
||||||
BlockPos pos = rememberedAddress.getPos();
|
|
||||||
Vec3d vec3d = new Vec3d(pos);
|
|
||||||
entityIn.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosWrapper(new BlockPos(vec3d)));
|
|
||||||
entityIn.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(vec3d, 0.5F, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.util.math.GlobalPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class DropPackageAtDestinationTask extends PackageDeliveryTask {
|
|
||||||
|
|
||||||
private GlobalPos rememberedAddress;
|
|
||||||
|
|
||||||
public DropPackageAtDestinationTask() {
|
|
||||||
super(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
if (!super.shouldExecute(worldIn, owner))
|
|
||||||
return false;
|
|
||||||
rememberedAddress = LogisticianHandler.getRememberedAddress(owner, getBox(owner).getAddress());
|
|
||||||
return rememberedAddress != null && rememberedAddress.getPos().withinDistance(owner.getPosition(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
LogisticianHandler.ponder(entityIn, "You're welcome.");
|
|
||||||
CardboardBoxEntity box = getBox(entityIn);
|
|
||||||
box.stopRiding();
|
|
||||||
Vec3d pos = VecHelper.getCenterOf(rememberedAddress.getPos());
|
|
||||||
box.setPosition(pos.x, pos.y, pos.z);
|
|
||||||
box.getPersistentData().putBoolean("Delivered", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.ai.brain.task.Task;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerProfession;
|
|
||||||
import net.minecraft.util.math.GlobalPos;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class ExpireWorkstationTask extends Task<VillagerEntity> {
|
|
||||||
|
|
||||||
private GlobalPos workstationPos;
|
|
||||||
|
|
||||||
public ExpireWorkstationTask() {
|
|
||||||
super(ImmutableMap.of(), 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
workstationPos = LogisticianHandler.getJobSite(owner);
|
|
||||||
return workstationPos.getPos().withinDistance(owner.getPosition(), 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
ServerWorld serverworld = worldIn.getServer().getWorld(workstationPos.getDimension());
|
|
||||||
if (!AllBlocks.LOGISTICIANS_TABLE.typeOf(serverworld.getBlockState(workstationPos.getPos()))) {
|
|
||||||
LogisticianHandler.ponder(entityIn, "Oh no! My workstation!");
|
|
||||||
entityIn.setVillagerData(entityIn.getVillagerData().withProfession(VillagerProfession.NONE).withLevel(1));
|
|
||||||
entityIn.resetBrain(serverworld);
|
|
||||||
entityIn.getPassengers().forEach(Entity::stopRiding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,146 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.mojang.datafixers.Dynamic;
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.Create;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.entity.ai.brain.task.DummyTask;
|
|
||||||
import net.minecraft.entity.ai.brain.task.FindInteractionAndLookTargetTask;
|
|
||||||
import net.minecraft.entity.ai.brain.task.FirstShuffledTask;
|
|
||||||
import net.minecraft.entity.ai.brain.task.LookAtEntityTask;
|
|
||||||
import net.minecraft.entity.ai.brain.task.StayNearPointTask;
|
|
||||||
import net.minecraft.entity.ai.brain.task.Task;
|
|
||||||
import net.minecraft.entity.ai.brain.task.UpdateActivityTask;
|
|
||||||
import net.minecraft.entity.ai.brain.task.WalkTowardsPosTask;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerProfession;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
|
||||||
import net.minecraft.nbt.INBT;
|
|
||||||
import net.minecraft.nbt.ListNBT;
|
|
||||||
import net.minecraft.nbt.NBTDynamicOps;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.SoundEvents;
|
|
||||||
import net.minecraft.util.math.GlobalPos;
|
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraft.village.PointOfInterestType;
|
|
||||||
import net.minecraftforge.common.util.Constants.NBT;
|
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
|
||||||
|
|
||||||
public class LogisticianHandler {
|
|
||||||
|
|
||||||
public static VillagerProfession LOGISTICIAN;
|
|
||||||
public static PointOfInterestType LOGISTICIANS_TABLE;
|
|
||||||
|
|
||||||
public static void registerPointsOfInterest(RegistryEvent.Register<PointOfInterestType> event) {
|
|
||||||
ImmutableList<BlockState> validStates = AllBlocks.LOGISTICIANS_TABLE.get().getStateContainer().getValidStates();
|
|
||||||
LOGISTICIANS_TABLE = new PointOfInterestType("logistician_table", ImmutableSet.copyOf(validStates), 1,
|
|
||||||
SoundEvents.ENTITY_VILLAGER_WORK_LIBRARIAN, 1)
|
|
||||||
.setRegistryName(new ResourceLocation(Create.ID, "logistician_table"));
|
|
||||||
event.getRegistry().register(LOGISTICIANS_TABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerVillagerProfessions(RegistryEvent.Register<VillagerProfession> event) {
|
|
||||||
LOGISTICIAN = new VillagerProfession("logistician", LOGISTICIANS_TABLE, ImmutableSet.of(), ImmutableSet.of())
|
|
||||||
.setRegistryName(new ResourceLocation(Create.ID, "logistician"));
|
|
||||||
event.getRegistry().register(LOGISTICIAN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ImmutableList<Pair<Integer, ? extends Task<? super VillagerEntity>>> work(float p_220639_1_) {
|
|
||||||
return ImmutableList.of(uselessTasks(), actualWorkTasks(),
|
|
||||||
Pair.of(10, new FindInteractionAndLookTargetTask(EntityType.PLAYER, 4)),
|
|
||||||
Pair.of(2, new StayNearPointTask(MemoryModuleType.JOB_SITE, p_220639_1_, 9, 100, 1200)),
|
|
||||||
Pair.of(3, new ExpireWorkstationTask()), Pair.of(99, new UpdateActivityTask()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Pair<Integer, Task<VillagerEntity>> actualWorkTasks() {
|
|
||||||
return Pair.of(5,
|
|
||||||
new FirstShuffledTask<>(ImmutableList.of(
|
|
||||||
Pair.of(new WalkToPackageTask(), 1),
|
|
||||||
Pair.of(new CollectPackageTask(), 1),
|
|
||||||
Pair.of(new WalkToWorkstationTask(), 1),
|
|
||||||
Pair.of(new LookupAddressTask(), 1),
|
|
||||||
Pair.of(new DeliverPackageToDestinationTask(), 1),
|
|
||||||
Pair.of(new DropPackageAtDestinationTask(), 1),
|
|
||||||
Pair.of(new WalkTowardsPosTask(MemoryModuleType.JOB_SITE, 1, 10), 5))));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Pair<Integer, Task<LivingEntity>> uselessTasks() {
|
|
||||||
return Pair.of(6,
|
|
||||||
new FirstShuffledTask<>(ImmutableList.of(Pair.of(new LookAtEntityTask(EntityType.VILLAGER, 8.0F), 2),
|
|
||||||
Pair.of(new LookAtEntityTask(EntityType.PLAYER, 8.0F), 2), Pair.of(new DummyTask(30, 60), 8))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GlobalPos getJobSite(VillagerEntity villager) {
|
|
||||||
CompoundNBT nbt = villager.getPersistentData();
|
|
||||||
String jobSiteKey = "JobSite";
|
|
||||||
if (!nbt.contains(jobSiteKey))
|
|
||||||
return null;
|
|
||||||
return GlobalPos.deserialize(new Dynamic<>(NBTDynamicOps.INSTANCE, nbt.getCompound(jobSiteKey)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setJobSite(VillagerEntity villager, GlobalPos pos) {
|
|
||||||
CompoundNBT nbt = villager.getPersistentData();
|
|
||||||
String jobSiteKey = "JobSite";
|
|
||||||
nbt.put(jobSiteKey, pos.serialize(NBTDynamicOps.INSTANCE));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rememberAddress(VillagerEntity villager, String address, GlobalPos pos) {
|
|
||||||
ListNBT list = getAddressList(villager);
|
|
||||||
|
|
||||||
for (Iterator<INBT> iterator = list.iterator(); iterator.hasNext();) {
|
|
||||||
INBT inbt = iterator.next();
|
|
||||||
if (((CompoundNBT) inbt).getString("Address").equals(address)) {
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.size() > 5)
|
|
||||||
list.remove(0);
|
|
||||||
|
|
||||||
CompoundNBT addedNBT = new CompoundNBT();
|
|
||||||
addedNBT.putString("Address", address);
|
|
||||||
addedNBT.put("Pos", pos.serialize(NBTDynamicOps.INSTANCE));
|
|
||||||
list.add(addedNBT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ListNBT getAddressList(VillagerEntity villager) {
|
|
||||||
CompoundNBT nbt = villager.getPersistentData();
|
|
||||||
String listKey = "MemorizedAddresses";
|
|
||||||
if (!nbt.contains(listKey))
|
|
||||||
nbt.put(listKey, new ListNBT());
|
|
||||||
ListNBT list = nbt.getList(listKey, NBT.TAG_COMPOUND);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static GlobalPos getRememberedAddress(VillagerEntity villager, String address) {
|
|
||||||
ListNBT list = getAddressList(villager);
|
|
||||||
|
|
||||||
for (INBT inbt : list) {
|
|
||||||
if (((CompoundNBT) inbt).getString("Address").equals(address)) {
|
|
||||||
Dynamic<INBT> dynamic = new Dynamic<>(NBTDynamicOps.INSTANCE, ((CompoundNBT) inbt).getCompound("Pos"));
|
|
||||||
return GlobalPos.deserialize(dynamic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ponder(VillagerEntity entityIn, String thought) {
|
|
||||||
Minecraft.getInstance().player.sendMessage(
|
|
||||||
new StringTextComponent("<" + entityIn.getDisplayName().getFormattedText() + "> " + thought));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,107 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllItems;
|
|
||||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.block.HorizontalBlock;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.SharedMonsterAttributes;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.entity.ai.brain.schedule.Activity;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerProfession;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.GlobalPos;
|
|
||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class LogisticiansTableBlock extends HorizontalBlock implements IWithTileEntity<LogisticiansTableTileEntity> {
|
|
||||||
|
|
||||||
public LogisticiansTableBlock() {
|
|
||||||
super(Properties.from(Blocks.SPRUCE_LOG));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTileEntity(BlockState state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
|
||||||
return new LogisticiansTableTileEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean ticksRandomly(BlockState state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
|
|
||||||
for (Entity entity : worldIn.getEntitiesWithinAABB(EntityType.VILLAGER, new AxisAlignedBB(pos).grow(10),
|
|
||||||
e -> ((VillagerEntity) e).getVillagerData().getProfession() == VillagerProfession.NONE)) {
|
|
||||||
|
|
||||||
VillagerEntity e = (VillagerEntity) entity;
|
|
||||||
float f = (float) e.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getValue();
|
|
||||||
e.setVillagerData(e.getVillagerData().withProfession(LogisticianHandler.LOGISTICIAN).withLevel(2));
|
|
||||||
e.getBrain().registerActivity(Activity.WORK, LogisticianHandler.work(f));
|
|
||||||
e.getBrain().setMemory(MemoryModuleType.JOB_SITE, GlobalPos.of(worldIn.getDimension().getType(), pos));
|
|
||||||
LogisticianHandler.setJobSite(e, GlobalPos.of(worldIn.getDimension().getType(), pos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> builder) {
|
|
||||||
builder.add(HORIZONTAL_FACING);
|
|
||||||
super.fillStateContainer(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean func_220074_n(BlockState state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
|
||||||
if (!(placer instanceof PlayerEntity))
|
|
||||||
return;
|
|
||||||
PlayerEntity player = (PlayerEntity) placer;
|
|
||||||
for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++) {
|
|
||||||
ItemStack itemStack = player.inventory.getStackInSlot(slot);
|
|
||||||
if (!AllItems.LOGISTICAL_DIAL.typeOf(itemStack))
|
|
||||||
continue;
|
|
||||||
if (!itemStack.hasTag())
|
|
||||||
continue;
|
|
||||||
withTileEntityDo(worldIn, pos, te -> te.setNetworkId(itemStack.getTag().getUniqueId("NetworkID")));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
||||||
return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite());
|
|
||||||
}
|
|
||||||
|
|
||||||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
||||||
return AllShapes.LOGISTICS_TABLE_BASE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
||||||
return AllShapes.LOGISTICS_TABLE.get(state.get(HORIZONTAL_FACING));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity;
|
|
||||||
|
|
||||||
public class LogisticiansTableTileEntity extends LogisticalActorTileEntity {
|
|
||||||
|
|
||||||
public LogisticiansTableTileEntity() {
|
|
||||||
super(AllTileEntities.LOGISTICIANS_TABLE.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.foundation.block.render.ColoredOverlayTileEntityRenderer;
|
|
||||||
import com.simibubi.create.foundation.utility.SuperByteBuffer;
|
|
||||||
import com.simibubi.create.foundation.utility.TessellatorHelper;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.entity.model.BookModel;
|
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
public class LogisticiansTableTileEntityRenderer extends TileEntityRenderer<LogisticiansTableTileEntity> {
|
|
||||||
|
|
||||||
public void render(LogisticiansTableTileEntity te, double x, double y, double z, float partialTicks,
|
|
||||||
int destroyStage) {
|
|
||||||
renderColoredIndicator(te, x, y, z);
|
|
||||||
renderBook(te, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void renderColoredIndicator(LogisticiansTableTileEntity te, double x, double y, double z) {
|
|
||||||
TessellatorHelper.prepareFastRender();
|
|
||||||
BlockState renderedState = AllBlocks.LOGISTICIANS_TABLE_INDICATOR.get().getDefaultState();
|
|
||||||
TessellatorHelper.begin(DefaultVertexFormats.BLOCK);
|
|
||||||
SuperByteBuffer render = ColoredOverlayTileEntityRenderer.render(getWorld(), te.getPos(), renderedState,
|
|
||||||
te.getColor());
|
|
||||||
Tessellator.getInstance().getBuffer().putBulkData(render.translate(x, y, z).build());
|
|
||||||
TessellatorHelper.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final ResourceLocation bookLocation = new ResourceLocation(
|
|
||||||
"textures/entity/enchanting_table_book.png");
|
|
||||||
private final BookModel bookModel = new BookModel();
|
|
||||||
|
|
||||||
protected void renderBook(LogisticiansTableTileEntity te, double x, double y, double z) {
|
|
||||||
RenderHelper.enableStandardItemLighting();
|
|
||||||
BlockState blockstate = te.getBlockState();
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
GlStateManager.translatef((float) x + 0.5F, (float) y + 1.0F + 0.0625F, (float) z + 0.5F);
|
|
||||||
float f = blockstate.get(BlockStateProperties.HORIZONTAL_FACING).rotateY().getHorizontalAngle();
|
|
||||||
GlStateManager.rotatef(-f, 0.0F, 1.0F, 0.0F);
|
|
||||||
GlStateManager.rotatef(67.5F, 0.0F, 0.0F, 1.0F);
|
|
||||||
GlStateManager.translatef(0.0F, -0.125F, 0.0F);
|
|
||||||
this.bindTexture(bookLocation);
|
|
||||||
GlStateManager.enableCull();
|
|
||||||
this.bookModel.render(0.0F, 0.1F, 0.9F, 1.2F, 0.0F, 0.0625F);
|
|
||||||
GlStateManager.disableCull();
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.GlobalPos;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class LookupAddressTask extends PackageDeliveryTask {
|
|
||||||
|
|
||||||
public LookupAddressTask() {
|
|
||||||
super(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
if (!super.shouldExecute(worldIn, owner))
|
|
||||||
return false;
|
|
||||||
CardboardBoxEntity box = getBox(owner);
|
|
||||||
GlobalPos rememberedAddress = LogisticianHandler.getRememberedAddress(owner, box.getAddress());
|
|
||||||
if (rememberedAddress != null)
|
|
||||||
return false;
|
|
||||||
return LogisticianHandler.getJobSite(owner).getPos().withinDistance(owner.getPosition(), 1.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
LogisticianHandler.ponder(entityIn, "Let's have a look...");
|
|
||||||
BlockPos tablePos = LogisticianHandler.getJobSite(entityIn).getPos();
|
|
||||||
if (!AllBlocks.LOGISTICIANS_TABLE.typeOf(worldIn.getBlockState(tablePos)))
|
|
||||||
return;
|
|
||||||
TileEntity te = worldIn.getTileEntity(tablePos);
|
|
||||||
if (te == null || !(te instanceof LogisticiansTableTileEntity))
|
|
||||||
return;
|
|
||||||
LogisticiansTableTileEntity lte = (LogisticiansTableTileEntity) te;
|
|
||||||
String address = getBox(entityIn).getAddress();
|
|
||||||
if (lte.getNetwork() == null)
|
|
||||||
return;
|
|
||||||
for (PackageFunnelTileEntity packageFunnelTileEntity : lte.getNetwork().packageTargets) {
|
|
||||||
for (String string : packageFunnelTileEntity.addresses) {
|
|
||||||
if (string.toLowerCase().equals(address.toLowerCase())) {
|
|
||||||
GlobalPos globalPos = GlobalPos.of(worldIn.getDimension().getType(), packageFunnelTileEntity.getPos());
|
|
||||||
LogisticianHandler.rememberAddress(entityIn, address, globalPos);
|
|
||||||
LogisticianHandler.ponder(entityIn, "I see!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LogisticianHandler.ponder(entityIn, "Hmm. Can't find that one");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleStatus;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.entity.ai.brain.task.Task;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class PackageDeliveryTask extends Task<VillagerEntity> {
|
|
||||||
|
|
||||||
public PackageDeliveryTask(int timeout) {
|
|
||||||
super(ImmutableMap.of(MemoryModuleType.LOOK_TARGET, MemoryModuleStatus.VALUE_ABSENT,
|
|
||||||
MemoryModuleType.WALK_TARGET, MemoryModuleStatus.VALUE_ABSENT), timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
return getBox(owner) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CardboardBoxEntity getBox(VillagerEntity owner) {
|
|
||||||
List<Entity> passengers = owner.getPassengers();
|
|
||||||
if (passengers.isEmpty())
|
|
||||||
return null;
|
|
||||||
Entity entity = passengers.get(0);
|
|
||||||
if (!(entity instanceof CardboardBoxEntity))
|
|
||||||
return null;
|
|
||||||
return (CardboardBoxEntity) entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,91 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.foundation.block.IWithTileEntity;
|
|
||||||
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
|
|
||||||
import com.simibubi.create.foundation.utility.AllShapes;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.ILogisticalCasingAttachment;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalCasingTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
|
||||||
import net.minecraft.world.IWorld;
|
|
||||||
import net.minecraft.world.IWorldReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class PackageFunnelBlock extends ProperDirectionalBlock implements IWithTileEntity<PackageFunnelTileEntity>, ILogisticalCasingAttachment {
|
|
||||||
|
|
||||||
public PackageFunnelBlock() {
|
|
||||||
super(Properties.from(Blocks.PISTON));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasTileEntity(BlockState state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
|
||||||
return new PackageFunnelTileEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
||||||
return getDefaultState().with(FACING, context.getFace());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos,
|
|
||||||
ISelectionContext context) {
|
|
||||||
if (context.getEntity() instanceof CardboardBoxEntity)
|
|
||||||
return VoxelShapes.empty();
|
|
||||||
return getShape(state, worldIn, pos, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
|
||||||
Direction facing = state.get(FACING);
|
|
||||||
BlockPos offset = pos.offset(facing.getOpposite());
|
|
||||||
BlockState blockState = worldIn.getBlockState(offset);
|
|
||||||
boolean isCasing = AllBlocks.LOGISTICAL_CASING.typeOf(blockState);
|
|
||||||
return isCasing;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
|
||||||
boolean isMoving) {
|
|
||||||
if (state.isValidPosition(worldIn, pos))
|
|
||||||
return;
|
|
||||||
|
|
||||||
TileEntity tileentity = state.hasTileEntity() ? worldIn.getTileEntity(pos) : null;
|
|
||||||
spawnDrops(state, worldIn, pos, tileentity);
|
|
||||||
worldIn.removeBlock(pos, false);
|
|
||||||
|
|
||||||
for (Direction direction : Direction.values())
|
|
||||||
worldIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
||||||
return AllShapes.PACKAGE_FUNNEL.get(state.get(FACING));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCasingUpdated(IWorld world, BlockPos pos, LogisticalCasingTileEntity te) {
|
|
||||||
Direction facing = world.getBlockState(pos).get(FACING).getOpposite();
|
|
||||||
if (!te.getPos().equals(pos.offset(facing)))
|
|
||||||
return;
|
|
||||||
withTileEntityDo(world, pos, PackageFunnelTileEntity::refreshAddressList);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,151 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import static com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity.ShippingInventory.RECEIVING;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
|
||||||
import com.simibubi.create.foundation.block.SyncedTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.LogisticalNetwork;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalActorTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.base.LogisticalCasingTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity;
|
|
||||||
import com.simibubi.create.modules.logistics.management.controller.LogisticalInventoryControllerTileEntity.ShippingInventory;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
|
||||||
import net.minecraft.tileentity.ITickableTileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
|
|
||||||
public class PackageFunnelTileEntity extends SyncedTileEntity implements ITickableTileEntity {
|
|
||||||
|
|
||||||
public static final int INSERTION_DELAY = 10;
|
|
||||||
|
|
||||||
protected int initialize;
|
|
||||||
protected List<String> addresses;
|
|
||||||
protected boolean waitingForSpace;
|
|
||||||
protected int cooldown;
|
|
||||||
protected AxisAlignedBB bb;
|
|
||||||
|
|
||||||
public PackageFunnelTileEntity() {
|
|
||||||
super(AllTileEntities.PACKAGE_FUNNEL.type);
|
|
||||||
addresses = new ArrayList<String>();
|
|
||||||
waitingForSpace = false;
|
|
||||||
cooldown = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void slotOpened() {
|
|
||||||
waitingForSpace = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad() {
|
|
||||||
super.onLoad();
|
|
||||||
initialize = 2;
|
|
||||||
bb = new AxisAlignedBB(getPos());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
|
|
||||||
// Initialize AFTER the actors to get a working network reference
|
|
||||||
if (initialize > -1)
|
|
||||||
initialize--;
|
|
||||||
if (initialize == 0) {
|
|
||||||
initialize();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cooldown > 0) {
|
|
||||||
cooldown--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (waitingForSpace)
|
|
||||||
return;
|
|
||||||
|
|
||||||
tryInsert();
|
|
||||||
cooldown = INSERTION_DELAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initialize() {
|
|
||||||
initialize = -1;
|
|
||||||
refreshAddressList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refreshAddressList() {
|
|
||||||
addresses.clear();
|
|
||||||
LogisticalCasingTileEntity casingTE = getCasingTE();
|
|
||||||
if (casingTE == null)
|
|
||||||
return;
|
|
||||||
for (LogisticalActorTileEntity actor : casingTE.getControllers()) {
|
|
||||||
addresses.add(actor.address);
|
|
||||||
if (actor.getNetwork() != null)
|
|
||||||
actor.getNetwork().addPackageTarget(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public LogisticalCasingTileEntity getCasingTE() {
|
|
||||||
BlockPos casingPos = pos.offset(getBlockState().get(BlockStateProperties.FACING).getOpposite());
|
|
||||||
TileEntity te = world.getTileEntity(casingPos);
|
|
||||||
if (te == null || !AllTileEntities.LOGISTICAL_CASING.typeOf(te))
|
|
||||||
return null;
|
|
||||||
LogisticalCasingTileEntity casingTE = (LogisticalCasingTileEntity) te;
|
|
||||||
return casingTE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tryInsert() {
|
|
||||||
for (CardboardBoxEntity e : world.getEntitiesWithinAABB(CardboardBoxEntity.class, bb, e -> {
|
|
||||||
if (e.isPassenger())
|
|
||||||
return false;
|
|
||||||
for (String address : addresses)
|
|
||||||
if (LogisticalNetwork.matchAddresses(address, e.getAddress()))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
})) {
|
|
||||||
LogisticalCasingTileEntity casingTE = getCasingTE();
|
|
||||||
if (casingTE == null)
|
|
||||||
return;
|
|
||||||
for (LogisticalActorTileEntity actor : casingTE.getControllers()) {
|
|
||||||
if (!(actor instanceof LogisticalInventoryControllerTileEntity))
|
|
||||||
continue;
|
|
||||||
if (LogisticalNetwork.matchAddresses(actor.address, e.getAddress())) {
|
|
||||||
LogisticalInventoryControllerTileEntity invTe = (LogisticalInventoryControllerTileEntity) actor;
|
|
||||||
if (!invTe.isReceiver())
|
|
||||||
continue;
|
|
||||||
ShippingInventory inventory = invTe.getInventory();
|
|
||||||
if (!inventory.getStackInSlot(RECEIVING).isEmpty()) {
|
|
||||||
waitingForSpace = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
inventory.insertItem(RECEIVING, e.getBox(), false);
|
|
||||||
e.remove();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
BlockPos casingPos = pos.offset(getBlockState().get(BlockStateProperties.FACING).getOpposite());
|
|
||||||
TileEntity te = world.getTileEntity(casingPos);
|
|
||||||
if (te == null || !AllTileEntities.LOGISTICAL_CASING.typeOf(te))
|
|
||||||
return;
|
|
||||||
LogisticalCasingTileEntity casingTE = (LogisticalCasingTileEntity) te;
|
|
||||||
for (LogisticalActorTileEntity actor : casingTE.getControllers()) {
|
|
||||||
if (actor.getNetwork() != null)
|
|
||||||
actor.getNetwork().removePackageTarget(this);
|
|
||||||
}
|
|
||||||
super.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAddressList() {
|
|
||||||
return addresses;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleStatus;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.WalkTarget;
|
|
||||||
import net.minecraft.entity.ai.brain.task.Task;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.BlockPosWrapper;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class WalkToPackageTask extends Task<VillagerEntity> {
|
|
||||||
private List<CardboardBoxEntity> foundPackages = new ArrayList<>();
|
|
||||||
private CardboardBoxEntity targetedPackage;
|
|
||||||
|
|
||||||
public WalkToPackageTask() {
|
|
||||||
super(ImmutableMap.of(MemoryModuleType.LOOK_TARGET, MemoryModuleStatus.VALUE_ABSENT,
|
|
||||||
MemoryModuleType.WALK_TARGET, MemoryModuleStatus.VALUE_ABSENT), 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
if (!worldIn.getEntitiesWithinAABB(CardboardBoxEntity.class, owner.getBoundingBox().grow(1.0D, 0.5D, 1.0D),
|
|
||||||
e -> !e.isPassenger() && !e.getPersistentData().getBoolean("Delivered")).isEmpty())
|
|
||||||
return false;
|
|
||||||
this.foundPackages = worldIn.getEntitiesWithinAABB(CardboardBoxEntity.class,
|
|
||||||
owner.getBoundingBox().grow(50.0D, 10.0D, 50.0D),
|
|
||||||
e -> !e.isPassenger() && !e.getPersistentData().getBoolean("Delivered"));
|
|
||||||
return !this.foundPackages.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
LogisticianHandler.ponder(entityIn, "Let's go to that package over there");
|
|
||||||
targetedPackage = this.foundPackages.get(worldIn.rand.nextInt(this.foundPackages.size()));
|
|
||||||
Vec3d vec3d = targetedPackage.getPositionVec();
|
|
||||||
entityIn.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosWrapper(new BlockPos(vec3d)));
|
|
||||||
entityIn.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(vec3d, 0.5F, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean shouldContinueExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
return !entityIn.getPosition().withinDistance(targetedPackage.getPosition(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package com.simibubi.create.modules.logistics.transport.villager;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
|
||||||
import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
|
|
||||||
import net.minecraft.entity.ai.brain.memory.WalkTarget;
|
|
||||||
import net.minecraft.entity.merchant.villager.VillagerEntity;
|
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.GlobalPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.server.ServerWorld;
|
|
||||||
|
|
||||||
public class WalkToWorkstationTask extends PackageDeliveryTask {
|
|
||||||
|
|
||||||
public WalkToWorkstationTask() {
|
|
||||||
super(60);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean shouldExecute(ServerWorld worldIn, VillagerEntity owner) {
|
|
||||||
if (!super.shouldExecute(worldIn, owner))
|
|
||||||
return false;
|
|
||||||
CardboardBoxEntity box = getBox(owner);
|
|
||||||
GlobalPos rememberedAddress = LogisticianHandler.getRememberedAddress(owner, box.getAddress());
|
|
||||||
return rememberedAddress == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
|
|
||||||
LogisticianHandler.ponder(entityIn, "I forgot where this address is at");
|
|
||||||
GlobalPos workstation = LogisticianHandler.getJobSite(entityIn);
|
|
||||||
if (workstation != null) {
|
|
||||||
BlockPos pos = workstation.getPos();
|
|
||||||
if (worldIn.isBlockPresent(pos)) {
|
|
||||||
BlockState blockState = worldIn.getBlockState(pos);
|
|
||||||
if (AllBlocks.LOGISTICIANS_TABLE.typeOf(blockState))
|
|
||||||
pos = pos.offset(blockState.get(BlockStateProperties.HORIZONTAL_FACING));
|
|
||||||
}
|
|
||||||
Vec3d vec = new Vec3d(pos);
|
|
||||||
entityIn.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(vec, 0.5F, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue