mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-25 14:24:28 +00:00
- Added MFR support for 1.6.4
- Improved API for blocks - NBT compound tags with non-identifier keys should now be output properly
This commit is contained in:
1 parent
e644398505
commit
e2b4f50dfc
97 files changed
+5307
-216
No files matched your search
@@ -1,21 +1,35 @@
|
||||
package minetweaker.api.minecraft;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import minetweaker.mc164.block.MCBlockDefinition;
|
||||
import minetweaker.mc164.block.MCSpecificBlock;
|
||||
import minetweaker.mc164.block.MCWorldBlock;
|
||||
import minetweaker.mc164.data.NBTConverter;
|
||||
import minetweaker.mc164.item.MCItemStack;
|
||||
import minetweaker.mc164.oredict.MCOreDictEntry;
|
||||
import minetweaker.mc164.player.MCPlayer;
|
||||
import minetweaker.mc164.world.MCDimension;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
@@ -24,6 +38,8 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
public class MineTweakerMC {
|
||||
private static final Map<Block, MCBlockDefinition> blockDefinitions = new HashMap<Block, MCBlockDefinition>();
|
||||
|
||||
private MineTweakerMC() {}
|
||||
|
||||
/**
|
||||
@@ -286,4 +302,91 @@ public class MineTweakerMC {
|
||||
|
||||
return (NBTTagCompound) NBTConverter.from(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block at the given position.
|
||||
*
|
||||
* @param blocks block access
|
||||
* @param x block x position
|
||||
* @param y block y position
|
||||
* @param z block z position
|
||||
* @return block instance
|
||||
*/
|
||||
public static IBlock getBlock(IBlockAccess blocks, int x, int y, int z) {
|
||||
return new MCWorldBlock(blocks, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the block definition for the given block.
|
||||
*
|
||||
* @param block block object
|
||||
* @return block definition
|
||||
*/
|
||||
public static IBlockDefinition getBlockDefinition(Block block) {
|
||||
if (!blockDefinitions.containsKey(block)) {
|
||||
blockDefinitions.put(block, new MCBlockDefinition(block));
|
||||
}
|
||||
return blockDefinitions.get(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the dimension instance for a given world.
|
||||
*
|
||||
* @param world world
|
||||
* @return dimension
|
||||
*/
|
||||
public static IDimension getDimension(World world) {
|
||||
if (world == null) return null;
|
||||
|
||||
return new MCDimension(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the given block.
|
||||
*
|
||||
* @param block MC block definition
|
||||
* @return MT block instance
|
||||
*/
|
||||
public static IBlock getBlockAnyMeta(Block block) {
|
||||
return new MCSpecificBlock(block, OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the given block.
|
||||
*
|
||||
* @param block MC block definition
|
||||
* @param meta block meta value
|
||||
* @return MT block instance
|
||||
*/
|
||||
public static IBlock getBlock(Block block, int meta) {
|
||||
return new MCSpecificBlock(block, meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the internal fluid stack of the given stack.
|
||||
*
|
||||
* @param stack MT liquid stack
|
||||
* @return MCF fluid stack
|
||||
*/
|
||||
public static FluidStack getLiquidStack(ILiquidStack stack) {
|
||||
return (FluidStack) stack.getInternal();
|
||||
}
|
||||
|
||||
public static int getBlockId(IBlockDefinition blockDefinition) {
|
||||
if (blockDefinition instanceof MCBlockDefinition) {
|
||||
return ((MCBlockDefinition) blockDefinition).getInternalId();
|
||||
} else {
|
||||
throw new IllegalArgumentException("block definition is not generated by MineTweaker");
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack toItemStack(IBlock block) {
|
||||
int mcBlockId = getBlockId(block.getDefinition());
|
||||
ItemStack result = new ItemStack(mcBlockId, 1, block.getMeta());
|
||||
IData data = block.getTileData();
|
||||
if (data != null) {
|
||||
result.setTagCompound(MineTweakerMC.getNBTCompound(data));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,8 @@ public class MineTweakerMod {
|
||||
private static final String[] REGISTRIES = {
|
||||
"minetweaker.mods.ic2.ClassRegistry",
|
||||
"minetweaker.mods.nei.ClassRegistry",
|
||||
"minetweaker.mods.gregtech.ClassRegistry"
|
||||
"minetweaker.mods.gregtech.ClassRegistry",
|
||||
"minetweaker.mods.mfr.ClassRegistry"
|
||||
};
|
||||
|
||||
@Mod.Instance(MODID)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.block;
|
||||
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCBlockDefinition implements IBlockDefinition {
|
||||
private final Block block;
|
||||
|
||||
public MCBlockDefinition(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public Block getInternalBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public int getInternalId() {
|
||||
return block.blockID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return block.getUnlocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.block;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import minetweaker.api.block.BlockPatternOr;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.block.IBlockPattern;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCItemBlock implements IBlock {
|
||||
private final ItemStack item;
|
||||
|
||||
public MCItemBlock(ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition getDefinition() {
|
||||
return MineTweakerMC.getBlockDefinition(Block.blocksList[item.itemID]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMeta() {
|
||||
return item.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getTileData() {
|
||||
if (item.stackTagCompound == null)
|
||||
return null;
|
||||
|
||||
return MineTweakerMC.getIData(item.stackTagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return item.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
return Collections.<IBlock>singletonList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
return getDefinition() == block.getDefinition()
|
||||
&& (getMeta() == OreDictionary.WILDCARD_VALUE || getMeta() == block.getMeta())
|
||||
&& (getTileData() == null || (block.getTileData() != null && block.getTileData().contains(getTileData())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockPattern or(IBlockPattern pattern) {
|
||||
return new BlockPatternOr(this, pattern);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.block;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import minetweaker.api.block.BlockPatternOr;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.block.IBlockPattern;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCSpecificBlock implements IBlock {
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
|
||||
public MCSpecificBlock(Block block, int meta) {
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition getDefinition() {
|
||||
return MineTweakerMC.getBlockDefinition(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMeta() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getTileData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
return Collections.<IBlock>singletonList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
return block.getDefinition() == getDefinition()
|
||||
&& (meta == OreDictionary.WILDCARD_VALUE || block.getMeta() == meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockPattern or(IBlockPattern pattern) {
|
||||
return new BlockPatternOr(this, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return block.getLocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.block;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import minetweaker.api.block.BlockPatternOr;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.block.IBlockDefinition;
|
||||
import minetweaker.api.block.IBlockPattern;
|
||||
import minetweaker.api.data.IData;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCWorldBlock implements IBlock {
|
||||
private final IBlockAccess blocks;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public MCWorldBlock(IBlockAccess blocks, int x, int y, int z) {
|
||||
this.blocks = blocks;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDefinition getDefinition() {
|
||||
return MineTweakerMC.getBlockDefinition(Block.blocksList[blocks.getBlockId(x, y, z)]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMeta() {
|
||||
return blocks.getBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IData getTileData() {
|
||||
TileEntity tileEntity = blocks.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity == null)
|
||||
return null;
|
||||
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
tileEntity.writeToNBT(nbt);
|
||||
return MineTweakerMC.getIData(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
int blockId = blocks.getBlockId(x, y, z);
|
||||
if (Item.itemsList[blockId] != null) {
|
||||
return (new ItemStack(blockId, 1, getMeta())).getDisplayName();
|
||||
} else {
|
||||
return Block.blocksList[blockId].getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlock> getBlocks() {
|
||||
return Collections.<IBlock>singletonList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IBlock block) {
|
||||
return getDefinition() == block.getDefinition()
|
||||
&& (getMeta() == OreDictionary.WILDCARD_VALUE || getMeta() == block.getMeta())
|
||||
&& (getTileData() == null || (block.getTileData() != null && block.getTileData().contains(getTileData())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockPattern or(IBlockPattern pattern) {
|
||||
return new BlockPatternOr(this, pattern);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class MCGame implements IGame {
|
||||
public static final MCGame INSTANCE = new MCGame();
|
||||
|
||||
private MCGame() {}
|
||||
|
||||
|
||||
@Override
|
||||
public List<IItemDefinition> getItems() {
|
||||
List<IItemDefinition> result = new ArrayList<IItemDefinition>();
|
||||
|
||||
@@ -9,6 +9,7 @@ package minetweaker.mc164.item;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.data.DataMap;
|
||||
import minetweaker.mc164.data.NBTConverter;
|
||||
import minetweaker.mc164.liquid.MCLiquidStack;
|
||||
@@ -19,11 +20,14 @@ import minetweaker.api.item.IItemDefinition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientItem;
|
||||
import minetweaker.api.item.IngredientOr;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
import minetweaker.mc164.actions.SetTranslationAction;
|
||||
import minetweaker.mc164.block.MCItemBlock;
|
||||
import minetweaker.util.ArrayUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
@@ -209,6 +213,11 @@ public class MCItemStack implements IItemStack {
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientItem(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
@@ -218,7 +227,7 @@ public class MCItemStack implements IItemStack {
|
||||
}
|
||||
|
||||
return internal.getItem() == stack.getItem()
|
||||
&& (wildcardSize || internal.stackSize == stack.stackSize)
|
||||
&& (wildcardSize || internal.stackSize >= stack.stackSize)
|
||||
&& (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE
|
||||
|| stack.getItemDamage() == internal.getItemDamage()
|
||||
|| (!stack.getHasSubtypes() && !stack.getItem().isDamageable()));
|
||||
@@ -241,6 +250,15 @@ public class MCItemStack implements IItemStack {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlock asBlock() {
|
||||
if (stack.itemID >= Block.blocksList.length || Block.blocksList[stack.itemID] == null) {
|
||||
throw new ClassCastException("This item is not a block");
|
||||
} else {
|
||||
return new MCItemBlock(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternal() {
|
||||
return stack;
|
||||
|
||||
@@ -15,6 +15,7 @@ import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemCondition;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IItemTransformer;
|
||||
import minetweaker.api.item.IngredientOr;
|
||||
import minetweaker.api.item.IngredientStack;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize;
|
||||
import static minetweaker.api.minecraft.MineTweakerMC.getItemStack;
|
||||
@@ -145,6 +146,11 @@ public class MCOreDictEntry implements IOreDictEntry {
|
||||
public IIngredient marked(String mark) {
|
||||
return new IngredientOreDict(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIngredient or(IIngredient ingredient) {
|
||||
return new IngredientOr(this, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(IItemStack item) {
|
||||
|
||||
@@ -159,6 +159,22 @@ public class MineTweakerHacks {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getPrivateStaticObject(Class<?> cls, String name) {
|
||||
try {
|
||||
Field field = cls.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return (T) field.get(null);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
|
||||
} catch (SecurityException ex) {
|
||||
|
||||
} catch (IllegalAccessException ex) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// #######################
|
||||
// ### Private Methods ###
|
||||
// #######################
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.util;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MineTweakerPlatformUtils {
|
||||
private MineTweakerPlatformUtils() {}
|
||||
|
||||
public static Class<? extends EntityLivingBase> getLivingEntityClass(String entityClassName) {
|
||||
try {
|
||||
Class<?> entityClass = Class.forName(entityClassName);
|
||||
if (!EntityLivingBase.class.isAssignableFrom(entityClass)) {
|
||||
throw new RuntimeException("Not an entity class: " + entityClassName);
|
||||
}
|
||||
return (Class<? extends EntityLivingBase>) entityClass;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException("entity class not found: " + entityClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.mc164.world;
|
||||
|
||||
import minetweaker.api.block.IBlock;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.api.world.IDimension;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class MCDimension implements IDimension {
|
||||
private final World world;
|
||||
|
||||
public MCDimension(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDay() {
|
||||
return world.isDaytime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightness(int x, int y, int z) {
|
||||
return world.getBlockLightValue(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDimension getDimension() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlock getBlock(int x, int y, int z) {
|
||||
return MineTweakerMC.getBlock(world, x, y, z);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user