Skip to content
This repository has been archived by the owner on Apr 22, 2019. It is now read-only.

Commit

Permalink
Move the getItemBlock functionality to a utils class, and clean up th…
Browse files Browse the repository at this point in the history
…e TileEntityBase class
  • Loading branch information
pahimar committed Oct 16, 2016
1 parent 8ee2cb8 commit a62d97a
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 226 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/pahimar/ee3/block/base/BlockBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.creativetab.CreativeTab;
import com.pahimar.ee3.init.ModBlocks;
import com.pahimar.ee3.item.base.ItemBlockEnumEE;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -39,8 +37,4 @@ public String getUnlocalizedName() {
public void initModelsAndVariants() {
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName().toString()));
}

public static ItemBlock getItemBlockFor(Block block) {
return block instanceof BlockEnumBase ? new ItemBlockEnumEE((BlockEnumBase) block) : new ItemBlock(block);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/pahimar/ee3/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.blacklist.BlacklistRegistry;
import com.pahimar.ee3.block.base.BlockBase;
import com.pahimar.ee3.command.CommandEE;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.handler.*;
Expand All @@ -12,6 +11,7 @@
import com.pahimar.ee3.reference.Files;
import com.pahimar.ee3.test.EETestSuite;
import com.pahimar.ee3.test.VanillaTestSuite;
import com.pahimar.ee3.util.BlockUtils;
import com.pahimar.ee3.util.FluidHelper;
import net.minecraft.block.Block;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -31,7 +31,7 @@ public void onPreInit(FMLPreInitializationEvent event) {

for (Block block : ModBlocks.getBlocks()) {
GameRegistry.register(block);
GameRegistry.register(BlockBase.getItemBlockFor(block), block.getRegistryName());
GameRegistry.register(BlockUtils.getItemBlockFor(block), block.getRegistryName());
}
EnergyValues.init();
AlchemyArrays.init();
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/pahimar/ee3/reference/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,8 @@ public static final class NBT {
public static final String UUID = "uuid";
public static final String DISPLAY = "display";
public static final String COLOR = "color";
public static final String STATE = "teState";
public static final String CUSTOM_NAME = "CustomName";
public static final String DIRECTION = "teDirection"; // Legacy from MC 1.7 and earlier
public static final String FACING = "teFacing";
public static final String OWNER = "owner";
public static final String OWNER_UUID_MOST_SIG = "ownerUUIDMostSig";
public static final String OWNER_UUID_LEAST_SIG = "ownerUUIDLeastSig";
public static final String ENERGY_VALUE = "energyValue";
}

Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/pahimar/ee3/tileentity/TileEntityBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.pahimar.ee3.tileentity;

import com.pahimar.ee3.reference.Names;
import com.sun.istack.internal.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;

import java.util.UUID;

public abstract class TileEntityBase extends TileEntity implements ITickable {

protected String customName;
protected UUID owner;

public TileEntityBase() {
customName = "";
owner = null;
}

public boolean hasCustomName() {
return customName != null && !customName.isEmpty();
}

@Nullable
public String getCustomName() {
return customName;
}

public void setCustomName(String customName) {
this.customName = customName;
}

public boolean hasOwner() {
return owner != null;
}

@Nullable
public UUID getOwner() {
return owner;
}

public void setOwner(UUID owner) {
this.owner = owner;
}

public void setOwner(EntityPlayer entityPlayer) {
if (entityPlayer != null) {
setOwner(entityPlayer.getUniqueID());
}
}

@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {

super.readFromNBT(nbtTagCompound);

if (nbtTagCompound.hasKey(Names.NBT.CUSTOM_NAME)) {
this.customName = nbtTagCompound.getString(Names.NBT.CUSTOM_NAME);
}

if (nbtTagCompound.hasUniqueId(Names.NBT.OWNER)) {
this.owner = nbtTagCompound.getUniqueId(Names.NBT.OWNER);
}
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound) {

super.writeToNBT(nbtTagCompound);

if (this.hasCustomName()) {
nbtTagCompound.setString(Names.NBT.CUSTOM_NAME, customName);
}

if (this.hasOwner()) {
nbtTagCompound.setUniqueId(Names.NBT.OWNER, owner);
}

return nbtTagCompound;
}
}
143 changes: 0 additions & 143 deletions src/main/java/com/pahimar/ee3/tileentity/TileEntityEE.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/com/pahimar/ee3/util/BlockUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pahimar.ee3.util;

import com.pahimar.ee3.block.base.BlockEnumBase;
import com.pahimar.ee3.item.base.ItemBlockEnumEE;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;

public class BlockUtils {

private BlockUtils() {}

public static ItemBlock getItemBlockFor(Block block) {
return block instanceof BlockEnumBase ? new ItemBlockEnumEE((BlockEnumBase) block) : new ItemBlock(block);
}
}
70 changes: 0 additions & 70 deletions src/main/java/com/pahimar/ee3/util/TileEntityDataHelper.java

This file was deleted.

0 comments on commit a62d97a

Please sign in to comment.