Skip to content

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Jul 4, 2017
1 parent 744fad8 commit ab14e92
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 82 deletions.
26 changes: 2 additions & 24 deletions src/main/java/knightminer/ceramics/Ceramics.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,6 @@ public class Ceramics {
FluidRegistry.enableUniversalBucket();
}

// makes oredict to int a bit easier in a couple other places
public static final String[] dyes = {
"White",
"Orange",
"Magenta",
"LightBlue",
"Yellow",
"Lime",
"Pink",
"Gray",
"LightGray",
"Cyan",
"Purple",
"Blue",
"Brown",
"Green",
"Red",
"Black"
};

@SuppressWarnings({"unchecked", "rawtypes"})
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
Config.load(event);
Expand Down Expand Up @@ -237,7 +216,7 @@ public static void registerItems(RegistryEvent.Register<Item> event) {
registerItemBlock(r, new ItemBlockEnum(clayHard));
registerItemBlock(r, new ItemBlockEnum(claySoft));
registerItemBlock(r, new ItemBlockEnum(clayWall));
registerItemBlock(r, new ItemBlockEnumSlab(claySlab));
registerItemBlock(r, new ItemBlockEnumSlab<>(claySlab));

// porcelain
registerItemBlock(r, new ItemBlockEnum(porcelain));
Expand Down Expand Up @@ -358,7 +337,7 @@ public static <T extends Block> T registerBlock(IForgeRegistry<Block> registry,
return block;
}

protected static <E extends Enum<E> & BlockEnumBase.IEnumMeta & IStringSerializable> BlockStairsEnum registerStairsFrom(IForgeRegistry<Block> registry, BlockEnumBase<E> block, E value, String name) {
protected static <E extends Enum<E> & BlockEnumBase.IEnumMeta & IStringSerializable> BlockStairsEnum<E> registerStairsFrom(IForgeRegistry<Block> registry, BlockEnumBase<E> block, E value, String name) {
return registerBlock(registry, new BlockStairsEnum<>(block, value), name);
}

Expand All @@ -377,7 +356,6 @@ public static <T extends ItemBlock> T registerItemBlock(IForgeRegistry<Item> reg
return item;
}

@SuppressWarnings("unchecked")
public static <T extends Item> T registerItem(IForgeRegistry<Item> registry, T block, String name) {
block.setUnlocalizedName(Util.prefix(name));
block.setRegistryName(Util.getResource(name));
Expand Down
69 changes: 35 additions & 34 deletions src/main/java/knightminer/ceramics/items/ItemClayBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public String getItemStackDisplayName(ItemStack stack) {
return I18n.translateToLocalFormatted(unloc + ".name", fluidStack.getLocalizedName());
}


/* Bucket behavior */

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
Expand Down Expand Up @@ -263,7 +266,8 @@ public void onItemDestroyed(PlayerDestroyItemEvent event) {
}
}

// container items

/* Container logic */

@Override
public ItemStack getContainerItem(ItemStack stack) {
Expand All @@ -278,25 +282,7 @@ public boolean hasContainerItem(ItemStack stack) {
return !doesBreak(stack);
}

@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase target, EnumHand hand) {
// only work if the bucket is empty and right clicking a cow
if(!hasFluid(stack) && target instanceof EntityCow && !player.capabilities.isCreativeMode) {
// if we have multiple buckets in the stack, move to a new slot
if(stack.getCount() > 1) {
stack.shrink(1);
ItemHandlerHelper.giveItemToPlayer(player, setSpecialFluid(new ItemStack(this), SpecialFluid.MILK));
}
else {
setSpecialFluid(stack, SpecialFluid.MILK);
}

return true;
}
return false;
}

public boolean doesBreak(ItemStack stack) {
private boolean doesBreak(ItemStack stack) {
// special fluids never breaks
if(hasSpecialFluid(stack)) {
return false;
Expand All @@ -311,6 +297,9 @@ public boolean doesBreak(ItemStack stack) {
return false;
}


/* Special fluid behavior */

/**
* Checks if the stack is not a regular dynamic bucket
* Used for sand, gravel, and milk
Expand All @@ -330,13 +319,13 @@ public SpecialFluid getSpecialFluid(ItemStack stack) {
return SpecialFluid.fromMeta(stack.getItemDamage());
}

// in case I change it later
public ItemStack setSpecialFluid(ItemStack stack, SpecialFluid fluid) {
stack.setItemDamage(fluid.getMeta());
return stack;
}

/* Fluids */

/* Standard fluid logic */

public FluidStack getFluid(ItemStack container) {
// milk logic, if milk is registered we use that basically
Expand Down Expand Up @@ -450,6 +439,7 @@ else if(!hasSpecialFluid(container)) {
return fluidStack;
}


/* Milk bucket logic */
/**
* Called when the player finishes using this Item (E.g. finishes eating.).
Expand Down Expand Up @@ -498,6 +488,25 @@ public EnumAction getItemUseAction(ItemStack stack) {
return getSpecialFluid(stack) == SpecialFluid.MILK ? EnumAction.DRINK : EnumAction.NONE;
}

// fill with milk from cows
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase target, EnumHand hand) {
// only work if the bucket is empty and right clicking a cow
if(!hasFluid(stack) && target instanceof EntityCow && !player.capabilities.isCreativeMode) {
// if we have multiple buckets in the stack, move to a new slot
if(stack.getCount() > 1) {
stack.shrink(1);
ItemHandlerHelper.giveItemToPlayer(player, setSpecialFluid(new ItemStack(this), SpecialFluid.MILK));
}
else {
setSpecialFluid(stack, SpecialFluid.MILK);
}

return true;
}
return false;
}


/**
* @return the fuel burn time for this itemStack in a furnace.
Expand All @@ -512,6 +521,10 @@ public int getItemBurnTime(ItemStack stack) {
}
return 0;
}


/* Misc */

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems) {
if (Config.bucketEnabled && this.isInCreativeTab(tab)) {
Expand Down Expand Up @@ -544,18 +557,6 @@ public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt)
return new FluidClayBucketWrapper(stack);
}

public ItemStack withFluid(Fluid fluid) {
ItemStack stack = new ItemStack(this, 1, 0);

// add fluid to NBT
NBTTagCompound tag = new NBTTagCompound();
tag.setTag(TAG_FLUIDS, new FluidStack(fluid, getCapacity()).writeToNBT(new NBTTagCompound()));
stack.setTagCompound(tag);

// return
return stack;
}

/**
* Special fluid types
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public int fill(FluidStack resource, boolean doFill) {
}

if (doFill) {
setFluid(resource.getFluid());
setFluid(resource);
}

return Fluid.BUCKET_VOLUME;
Expand Down
33 changes: 10 additions & 23 deletions src/main/java/knightminer/ceramics/plugin/jei/JEIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@
import knightminer.ceramics.Ceramics;
import knightminer.ceramics.library.Config;
import knightminer.ceramics.library.Util;
import mezz.jei.api.IJeiRuntime;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.ISubtypeRegistry;
import mezz.jei.api.ingredients.IModIngredientRegistration;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.translation.I18n;

@SuppressWarnings("deprecation")
@mezz.jei.api.JEIPlugin
public class JEIPlugin implements IModPlugin {

@SuppressWarnings("deprecation")
@Override
public void register(IModRegistry registry) {
// descriptions

if(Config.bucketEnabled) {
registry.addDescription(new ItemStack(Ceramics.clayBucket), Util.prefix("jei.bucket"));
registry.addIngredientInfo(new ItemStack(Ceramics.clayBucket), ItemStack.class, Util.prefix("jei.bucket"));
}

if(Config.barrelEnabled) {
ArrayList<ItemStack> barrels = new ArrayList<ItemStack>();
ArrayList<ItemStack> extensions = new ArrayList<ItemStack>();
ArrayList<ItemStack> barrels = new ArrayList<>();
ArrayList<ItemStack> extensions = new ArrayList<>();

// basic barrels
barrels.add(new ItemStack(Ceramics.clayBarrel, 1, 0));
Expand All @@ -40,31 +37,21 @@ public void register(IModRegistry registry) {
extensions.add(new ItemStack(Ceramics.clayBarrelStainedExtension, 1, color.getMetadata()));
}

registry.addDescription(barrels, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.base"), Config.barrelClayCapacity));
registry.addDescription(extensions, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.extension"), Config.barrelClayCapacity));
registry.addIngredientInfo(barrels, ItemStack.class, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.base"), Config.barrelClayCapacity));
registry.addIngredientInfo(extensions, ItemStack.class, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.extension"), Config.barrelClayCapacity));

// porcelain ones, have a larger capacity so a separate entry
if(Config.porcelainEnabled) {
ArrayList<ItemStack> porcelainBarrels = new ArrayList<ItemStack>();
ArrayList<ItemStack> porcelainExtensions = new ArrayList<ItemStack>();
ArrayList<ItemStack> porcelainBarrels = new ArrayList<>();
ArrayList<ItemStack> porcelainExtensions = new ArrayList<>();
for(EnumDyeColor color : EnumDyeColor.values()) {
porcelainBarrels.add(new ItemStack(Ceramics.porcelainBarrel, 1, color.getMetadata()));
porcelainExtensions.add(new ItemStack(Ceramics.porcelainBarrelExtension, 1, color.getMetadata()));
}

registry.addDescription(porcelainBarrels, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.porcelain.base"), Config.barrelPorcelainCapacity));
registry.addDescription(porcelainExtensions, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.porcelain.extension"), Config.barrelPorcelainCapacity));
registry.addIngredientInfo(porcelainBarrels, ItemStack.class, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.porcelain.base"), Config.barrelPorcelainCapacity));
registry.addIngredientInfo(porcelainExtensions, ItemStack.class, I18n.translateToLocalFormatted(Util.prefix("jei.barrel.porcelain.extension"), Config.barrelPorcelainCapacity));
}
}
}

@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {}

@Override
public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) {}

@Override
public void registerIngredients(IModIngredientRegistration registry) {}

}

0 comments on commit ab14e92

Please sign in to comment.