Model fixes for wireless grid
This commit is contained in:
@@ -2,16 +2,13 @@ package refinedstorage.item;
|
||||
|
||||
import cofh.api.energy.ItemEnergyContainer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.IItemPropertyGetter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorage;
|
||||
@@ -29,6 +26,8 @@ public class ItemWirelessGrid extends ItemEnergyContainer {
|
||||
public static final String NBT_SORTING_DIRECTION = "SortingDirection";
|
||||
public static final String NBT_SEARCH_BOX_MODE = "SearchBoxMode";
|
||||
|
||||
public static final int RANGE = 64;
|
||||
|
||||
public static final int USAGE_OPEN = 30;
|
||||
public static final int USAGE_PULL = 3;
|
||||
public static final int USAGE_PUSH = 3;
|
||||
@@ -36,6 +35,13 @@ public class ItemWirelessGrid extends ItemEnergyContainer {
|
||||
public ItemWirelessGrid() {
|
||||
super(3200);
|
||||
|
||||
addPropertyOverride(new ResourceLocation("connected"), new IItemPropertyGetter() {
|
||||
@Override
|
||||
public float apply(ItemStack stack, World world, EntityLivingBase entity) {
|
||||
return canOpenWirelessGrid(world, entity, stack) ? 1.0f : 0.0f;
|
||||
}
|
||||
});
|
||||
|
||||
setMaxDamage(3200);
|
||||
setHasSubtypes(false);
|
||||
setCreativeTab(RefinedStorage.TAB);
|
||||
@@ -70,7 +76,7 @@ public class ItemWirelessGrid extends ItemEnergyContainer {
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) {
|
||||
list.add(I18n.translateToLocalFormatted("misc.refinedstorage:energy_stored", getEnergyStored(stack), getMaxEnergyStored(stack)));
|
||||
|
||||
if (isValid(stack)) {
|
||||
if (canOpenWirelessGrid(player.worldObj, player, stack)) {
|
||||
list.add(I18n.translateToLocalFormatted("misc.refinedstorage:wireless_grid.tooltip.0", getX(stack)));
|
||||
list.add(I18n.translateToLocalFormatted("misc.refinedstorage:wireless_grid.tooltip.1", getY(stack)));
|
||||
list.add(I18n.translateToLocalFormatted("misc.refinedstorage:wireless_grid.tooltip.2", getZ(stack)));
|
||||
@@ -101,24 +107,12 @@ public class ItemWirelessGrid extends ItemEnergyContainer {
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
if (!world.isRemote) {
|
||||
if (isValid(stack)) {
|
||||
if (isInRange(stack, player)) {
|
||||
TileEntity tile = world.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)));
|
||||
if (!world.isRemote && canOpenWirelessGrid(world, player, stack)) {
|
||||
TileController tile = (TileController) world.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)));
|
||||
|
||||
if (tile instanceof TileController) {
|
||||
((TileController) tile).onOpenWirelessGrid(player, hand);
|
||||
tile.onOpenWirelessGrid(player, hand);
|
||||
|
||||
return new ActionResult(EnumActionResult.SUCCESS, stack);
|
||||
} else {
|
||||
player.addChatComponentMessage(new TextComponentString(I18n.translateToLocal("misc.refinedstorage:wireless_grid.not_found")));
|
||||
}
|
||||
} else {
|
||||
player.addChatComponentMessage(new TextComponentString(I18n.translateToLocal("misc.refinedstorage:wireless_grid.out_of_range")));
|
||||
}
|
||||
} else {
|
||||
player.addChatComponentMessage(new TextComponentString(I18n.translateToLocal("misc.refinedstorage:wireless_grid.not_found")));
|
||||
}
|
||||
return new ActionResult(EnumActionResult.SUCCESS, stack);
|
||||
}
|
||||
|
||||
return new ActionResult(EnumActionResult.PASS, stack);
|
||||
@@ -148,14 +142,33 @@ public class ItemWirelessGrid extends ItemEnergyContainer {
|
||||
return stack.getTagCompound().getInteger(NBT_SEARCH_BOX_MODE);
|
||||
}
|
||||
|
||||
public static boolean isInRange(ItemStack stack, EntityPlayer player) {
|
||||
return (int) Math.sqrt(Math.pow(getX(stack) - player.posX, 2) + Math.pow(getY(stack) - player.posY, 2) + Math.pow(getZ(stack) - player.posZ, 2)) < 64;
|
||||
public static boolean isInRange(ItemStack stack, EntityLivingBase entity) {
|
||||
return (int) Math.sqrt(Math.pow(getX(stack) - entity.posX, 2) + Math.pow(getY(stack) - entity.posY, 2) + Math.pow(getZ(stack) - entity.posZ, 2)) < RANGE;
|
||||
}
|
||||
|
||||
public static boolean isValid(ItemStack stack) {
|
||||
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_CONTROLLER_X) && stack.getTagCompound().hasKey(NBT_CONTROLLER_Y) && stack.getTagCompound().hasKey(NBT_CONTROLLER_Z);
|
||||
public static boolean canOpenWirelessGrid(World world, EntityLivingBase entity, ItemStack stack) {
|
||||
if (entity != null && stack.hasTagCompound()
|
||||
&& stack.getTagCompound().hasKey(NBT_CONTROLLER_X)
|
||||
&& stack.getTagCompound().hasKey(NBT_CONTROLLER_Y)
|
||||
&& stack.getTagCompound().hasKey(NBT_CONTROLLER_Z)
|
||||
&& stack.getTagCompound().hasKey(NBT_SORTING_DIRECTION)
|
||||
&& stack.getTagCompound().hasKey(NBT_SORTING_TYPE)
|
||||
&& stack.getTagCompound().hasKey(NBT_SEARCH_BOX_MODE)) {
|
||||
if (world == null) {
|
||||
world = entity.worldObj;
|
||||
}
|
||||
|
||||
int x = getX(stack);
|
||||
int y = getY(stack);
|
||||
int z = getZ(stack);
|
||||
|
||||
return isInRange(stack, entity) && world.getTileEntity(new BlockPos(x, y, z)) instanceof TileController;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return "item." + RefinedStorage.ID + ":wireless_grid";
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package refinedstorage.proxy;
|
||||
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMap;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -14,7 +12,10 @@ import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.block.EnumControllerType;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.block.EnumStorageType;
|
||||
import refinedstorage.item.*;
|
||||
import refinedstorage.item.ItemCore;
|
||||
import refinedstorage.item.ItemProcessor;
|
||||
import refinedstorage.item.ItemStorageDisk;
|
||||
import refinedstorage.item.ItemStoragePart;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
@Override
|
||||
@@ -52,11 +53,6 @@ public class ClientProxy extends CommonProxy {
|
||||
new ResourceLocation("refinedstorage:destruction_core")
|
||||
);
|
||||
|
||||
ModelBakery.registerItemVariants(RefinedStorageItems.WIRELESS_GRID,
|
||||
new ResourceLocation("refinedstorage:wireless_grid_connected"),
|
||||
new ResourceLocation("refinedstorage:wireless_grid_disconnected")
|
||||
);
|
||||
|
||||
// Items
|
||||
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_1K, new ModelResourceLocation("refinedstorage:1k_storage_disk", "inventory"));
|
||||
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.STORAGE_DISK, ItemStorageDisk.TYPE_4K, new ModelResourceLocation("refinedstorage:4k_storage_disk", "inventory"));
|
||||
@@ -84,16 +80,7 @@ public class ClientProxy extends CommonProxy {
|
||||
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.CORE, ItemCore.TYPE_CONSTRUCTION, new ModelResourceLocation("refinedstorage:construction_core", "inventory"));
|
||||
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.CORE, ItemCore.TYPE_DESTRUCTION, new ModelResourceLocation("refinedstorage:destruction_core", "inventory"));
|
||||
|
||||
ModelLoader.setCustomMeshDefinition(RefinedStorageItems.WIRELESS_GRID, new ItemMeshDefinition() {
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack) {
|
||||
if (ItemWirelessGrid.isValid(stack)) {
|
||||
return new ModelResourceLocation("refinedstorage:wireless_grid_connected", "inventory");
|
||||
} else {
|
||||
return new ModelResourceLocation("refinedstorage:wireless_grid_disconnected", "inventory");
|
||||
}
|
||||
}
|
||||
});
|
||||
ModelLoader.setCustomModelResourceLocation(RefinedStorageItems.WIRELESS_GRID, 0, new ModelResourceLocation("refinedstorage:wireless_grid", "inventory"));
|
||||
|
||||
// Blocks
|
||||
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(RefinedStorageBlocks.CABLE), 0, new ModelResourceLocation("refinedstorage:cable", "inventory"));
|
||||
|
||||
20
src/main/resources/assets/refinedstorage/models/item/wireless_grid.json
Executable file
20
src/main/resources/assets/refinedstorage/models/item/wireless_grid.json
Executable file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "refinedstorage:items/wireless_grid_disconnected"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"predicate": {
|
||||
"connected": 0
|
||||
},
|
||||
"model": "refinedstorage:item/wireless_grid_disconnected"
|
||||
},
|
||||
{
|
||||
"predicate": {
|
||||
"connected": 1
|
||||
},
|
||||
"model": "refinedstorage:item/wireless_grid_connected"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user