Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Entity Inventory" option to entity aspects on world item tunnels #254

Draft
wants to merge 9 commits into
base: master-1.16
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repo/*
*.ipr
*.iws
out/*
run*.launch
keystore.jks

# Ignore mac-specific file(s)
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
url = "https://maven.minecraftforge.net/"
}
}
dependencies {
Expand All @@ -23,6 +23,7 @@ plugins {

apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'jacoco'
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_version=1.8.9
minecraft_version=1.16.5
forge_version=36.2.5
forge_version=36.2.34
mcp_mappings_channel=snapshot
mcp_mappings_version=20201028-1.16.3
cyclopscore_version=1.11.6-64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import org.cyclops.cyclopscore.proxy.IClientProxy;
import org.cyclops.cyclopscore.proxy.ICommonProxy;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.api.part.aspect.IAspect;
import org.cyclops.integrateddynamics.core.part.aspect.AspectRegistry;
import org.cyclops.integrateddynamics.infobook.OnTheDynamicsOfIntegrationBook;
import org.cyclops.integratedtunnels.api.world.IBlockBreakHandlerRegistry;
import org.cyclops.integratedtunnels.api.world.IBlockPlaceHandlerRegistry;
import org.cyclops.integratedtunnels.api.world.IEntityIItemTargetProxyRegistry;
import org.cyclops.integratedtunnels.api.world.IEntityInventoryTypeRegistry;
import org.cyclops.integratedtunnels.capability.ingredient.TunnelIngredientComponentCapabilities;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
Expand All @@ -31,6 +32,10 @@
import org.cyclops.integratedtunnels.core.world.BlockBreakHandlers;
import org.cyclops.integratedtunnels.core.world.BlockBreakPlaceRegistry;
import org.cyclops.integratedtunnels.core.world.BlockPlaceHandlers;
import org.cyclops.integratedtunnels.core.world.EntityIItemTargetProxies;
import org.cyclops.integratedtunnels.core.world.EntityIItemTargetProxyRegistry;
import org.cyclops.integratedtunnels.core.world.EntityInventoryTypeRegistry;
import org.cyclops.integratedtunnels.core.world.EntityInventoryTypes;
import org.cyclops.integratedtunnels.item.ItemDummyPickAxeConfig;
import org.cyclops.integratedtunnels.part.PartTypes;
import org.cyclops.integratedtunnels.part.aspect.TunnelAspects;
Expand All @@ -57,6 +62,8 @@ public IntegratedTunnels() {
// Registries
getRegistryManager().addRegistry(IBlockBreakHandlerRegistry.class, BlockBreakHandlerRegistry.getInstance());
getRegistryManager().addRegistry(IBlockPlaceHandlerRegistry.class, BlockBreakPlaceRegistry.getInstance());
getRegistryManager().addRegistry(IEntityInventoryTypeRegistry.class, EntityInventoryTypeRegistry.getInstance());
getRegistryManager().addRegistry(IEntityIItemTargetProxyRegistry.class, EntityIItemTargetProxyRegistry.getInstance());

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate);
}
Expand All @@ -67,6 +74,8 @@ public void onRegistriesCreate(RegistryEvent.NewRegistry event) {
PartTypes.load();
BlockBreakHandlers.load();
BlockPlaceHandlers.load();
EntityInventoryTypes.load();
EntityIItemTargetProxies.load();
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/cyclops/integratedtunnels/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.cyclops.cyclopscore.helper.MinecraftHelpers;

import net.minecraft.util.Direction;

/**
* Class that can hold basic static things that are better not hard-coded
* like mod details, texture paths, ID's...
Expand All @@ -20,4 +22,8 @@ public class Reference {
public static final String MOD_FORGE = "forge";
public static final String MOD_CYCLOPSCORE = "cyclopscore";
public static final String MOD_INTEGRATEDDYNAMICS = "integrateddynamics";

// Entity Inventory Sidings
public static final Direction ENTITY_ARMOR_SIDE = Direction.NORTH;
public static final Direction ENTITY_INVENTORY_SIDE = Direction.UP;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cyclops.integratedtunnels.api.world;

import javax.annotation.Nonnull;

/**
* An entity inventory type.
* For example: armor slots, inventory slots, ender chest.
* Other mods may add extra inventory types.
*
* Effectively an enum key; used as entries in a registry.
*
* @author met4000
*/
public abstract class EntityInventoryTypeBase {

@Nonnull
public abstract String getName(); // TODO allow for localisation

@Override
public final boolean equals(Object o) {
if (o == null) return false;
if (!(o instanceof EntityInventoryTypeBase)) return false;
return getName().equals(((EntityInventoryTypeBase)o).getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.cyclops.integratedtunnels.api.world;

import javax.annotation.Nullable;

import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import org.cyclops.integratedtunnels.part.aspect.IItemTarget;
import org.cyclops.integratedtunnels.part.aspect.ITunnelTransfer;

import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;

/**
* Proxy that can produce an IItemTarget for an Entity.
* @author met4000
*/
public interface IEntityIItemTargetProxy {

public boolean shouldApply(ITunnelTransfer transfer, INetwork network,
@Nullable Entity entity, Direction side, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState);

public IItemTarget evaluate(ITunnelTransfer transfer, INetwork network,
@Nullable Entity entity, Direction side, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.cyclops.integratedtunnels.api.world;

import java.util.Collection;

import javax.annotation.Nullable;

import org.cyclops.cyclopscore.init.IRegistry;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import org.cyclops.integratedtunnels.part.aspect.ITunnelTransfer;

import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;

/**
* A registry for entity IItemTarget proxies.
* @author met4000
*/
public interface IEntityIItemTargetProxyRegistry extends IRegistry {

// Multiple handlers may exist that return `true` for #shouldApply; the first one found should be used.
public IEntityIItemTargetProxy register(IEntityIItemTargetProxy proxy);

public Collection<IEntityIItemTargetProxy> getProxies();

@Nullable
public IEntityIItemTargetProxy getHandler(ITunnelTransfer transfer, INetwork network, @Nullable Entity entity,
Direction side, int slot, IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState);

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.cyclops.integratedtunnels.api.world;

import java.util.Collection;

import org.cyclops.cyclopscore.init.IRegistry;

/**
* Collection of IEntityInventoryTypes.
* @author met4000
*/
public interface IEntityInventoryTypeRegistry extends IRegistry {

public EntityInventoryTypeBase register(EntityInventoryTypeBase type);

public Collection<EntityInventoryTypeBase> getTypes();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.cyclops.integratedtunnels.core.world;

import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.IntegratedTunnels;
import org.cyclops.integratedtunnels.Reference;
import org.cyclops.integratedtunnels.api.world.IEntityIItemTargetProxyRegistry;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import org.cyclops.integratedtunnels.part.aspect.IItemTarget;
import org.cyclops.integratedtunnels.part.aspect.ITunnelTransfer;
import org.cyclops.integratedtunnels.part.aspect.ItemTargetCapabilityProvider;

import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;

/**
* Collection of Entity IItemTarget proxies.
* @author met4000
*/
public class EntityIItemTargetProxies {

public static final IEntityIItemTargetProxyRegistry REGISTRY = IntegratedTunnels._instance.getRegistryManager()
.getRegistry(IEntityIItemTargetProxyRegistry.class);

public static void load() {
REGISTRY.register(new EntityIItemTargetProxyInventoryTypeBase(EntityInventoryTypes.SIDED) {
@Override
public IItemTarget evaluate(ITunnelTransfer transfer, INetwork network, Entity entity, Direction side, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, PartStateRoundRobin<?> partState) {
return new ItemTargetCapabilityProvider(transfer, network, entity, side,
slot, itemStackMatcher, partTarget, properties, partState);
}
});

REGISTRY.register(new EntityIItemTargetProxySided(EntityInventoryTypes.ARMOR, Reference.ENTITY_ARMOR_SIDE));
REGISTRY.register(new EntityIItemTargetProxySided(EntityInventoryTypes.INVENTORY, Reference.ENTITY_INVENTORY_SIDE));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cyclops.integratedtunnels.core.world;

import org.cyclops.integratedtunnels.IntegratedTunnels;
import org.cyclops.integratedtunnels.api.world.EntityInventoryTypeBase;
import org.cyclops.integratedtunnels.api.world.IEntityIItemTargetProxy;
import org.cyclops.integratedtunnels.api.world.IEntityInventoryTypeRegistry;

/**
* Registers the IEntityInventoryType with the EntityInventoryTypeRegistry.
* @author met4000
*/
public abstract class EntityIItemTargetProxyBase implements IEntityIItemTargetProxy {

private static final IEntityInventoryTypeRegistry REGISTRY = IntegratedTunnels._instance.getRegistryManager()
.getRegistry(IEntityInventoryTypeRegistry.class);

protected final EntityInventoryTypeBase inventoryType;

public EntityIItemTargetProxyBase(EntityInventoryTypeBase inventoryType) {
this.inventoryType = REGISTRY.register(inventoryType);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.cyclops.integratedtunnels.core.world;

import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.world.EntityInventoryTypeBase;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import org.cyclops.integratedtunnels.part.aspect.ITunnelTransfer;
import org.cyclops.integratedtunnels.part.aspect.TunnelAspectWriteBuilders.World;

import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;

/**
* An IItemTarget proxy to access a sided entity.
* @author met4000
*/
public abstract class EntityIItemTargetProxyInventoryTypeBase extends EntityIItemTargetProxyBase {

public EntityIItemTargetProxyInventoryTypeBase(EntityInventoryTypeBase inventoryType) {
super(inventoryType);
}

@Override
public boolean shouldApply(ITunnelTransfer transfer, INetwork network, Entity entity, Direction side, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, PartStateRoundRobin<?> partState) {
return inventoryType.getName().equals(properties.getValue(World.PROPERTY_ENTITYINVENTORY).getRawValue());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.cyclops.integratedtunnels.core.world;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import javax.annotation.Nullable;

import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.world.IEntityIItemTargetProxy;
import org.cyclops.integratedtunnels.api.world.IEntityIItemTargetProxyRegistry;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import org.cyclops.integratedtunnels.part.aspect.ITunnelTransfer;

import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;

/**
* Implementation of {@link IEntityIItemTargetProxyRegistry}
* @author met4000
*/
public class EntityIItemTargetProxyRegistry implements IEntityIItemTargetProxyRegistry {

private static EntityIItemTargetProxyRegistry INSTANCE = new EntityIItemTargetProxyRegistry();

// linked list used for constant append time
private final Collection<IEntityIItemTargetProxy> proxies = new LinkedList<IEntityIItemTargetProxy>();

private EntityIItemTargetProxyRegistry() {}

public static EntityIItemTargetProxyRegistry getInstance() {
return INSTANCE;
}

@Override
public IEntityIItemTargetProxy register(IEntityIItemTargetProxy proxy) {
proxies.add(proxy);
return proxy;
}

@Override
public Collection<IEntityIItemTargetProxy> getProxies() {
return Collections.unmodifiableCollection(proxies);
}

@Nullable
@Override
public IEntityIItemTargetProxy getHandler(ITunnelTransfer transfer, INetwork network, @Nullable Entity entity,
Direction side, int slot, IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
for (IEntityIItemTargetProxy proxy : getProxies()) {
if (proxy.shouldApply(transfer, network, entity, side, slot, itemStackMatcher, partTarget, properties, partState)) {
return proxy;
}
}
return null;
}

}
Loading