mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-23 03:49:22 +01:00
Did a thing with a stuff :3
This commit is contained in:
parent
089ea9956a
commit
4b3359eb1e
4 changed files with 0 additions and 292 deletions
|
@ -1,133 +0,0 @@
|
|||
package ellpeck.actuallyadditions.blocks;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import ellpeck.actuallyadditions.blocks.multi.IMultiBlock;
|
||||
import ellpeck.actuallyadditions.blocks.multi.MultiBlockHelper;
|
||||
import ellpeck.actuallyadditions.util.BlockUtil;
|
||||
import ellpeck.actuallyadditions.util.INameableItem;
|
||||
import ellpeck.actuallyadditions.util.ModUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockOreFactory extends BlockContainerBase implements INameableItem, IMultiBlock{
|
||||
|
||||
public BlockOreFactory(){
|
||||
super(Material.rock);
|
||||
this.setHarvestLevel("pickaxe", 0);
|
||||
this.setHardness(4.5F);
|
||||
this.setResistance(20.0F);
|
||||
this.setStepSound(soundTypeStone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int par2){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int side, int meta){
|
||||
return this.blockIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iconReg){
|
||||
this.blockIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
|
||||
if(!world.isRemote){
|
||||
//TODO
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z){
|
||||
this.makeMultiBlock(world, x, y, z, world.getBlock(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block block){
|
||||
this.makeMultiBlock(world, x, y, z, block);
|
||||
}
|
||||
|
||||
private void makeMultiBlock(World world, int x, int y, int z, Block block){
|
||||
if(block instanceof IMultiBlock){
|
||||
MultiBlockHelper.createMultiBlock((IMultiBlock)block, world, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(){
|
||||
return "blockOreFactory";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block[] getNeededBlocks(){
|
||||
return new Block[]{this};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getCore(){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeHor(){
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeVer(){
|
||||
return 5;
|
||||
}
|
||||
|
||||
public static class TheItemBlock extends ItemBlock{
|
||||
|
||||
private Block theBlock;
|
||||
|
||||
public TheItemBlock(Block block){
|
||||
super(block);
|
||||
this.theBlock = block;
|
||||
this.setHasSubtypes(false);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRarity getRarity(ItemStack stack){
|
||||
return EnumRarity.uncommon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack){
|
||||
return this.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) {
|
||||
BlockUtil.addInformation(theBlock, list, 3, "");
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage){
|
||||
return damage;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -82,8 +82,6 @@ public class InitBlocks{
|
|||
|
||||
public static Block blockXPSolidifier;
|
||||
|
||||
public static Block blockOreFactory;
|
||||
|
||||
public static void init(){
|
||||
ModUtil.LOGGER.info("Initializing Blocks...");
|
||||
|
||||
|
@ -103,9 +101,6 @@ public class InitBlocks{
|
|||
blockTestifiBucksWhiteSlab = new BlockSlabs("blockTestifiBucksWhiteSlab", blockTestifiBucksWhiteWall);
|
||||
BlockUtil.register(blockTestifiBucksWhiteSlab, BlockSlabs.TheItemBlock.class);
|
||||
|
||||
blockOreFactory = new BlockOreFactory();
|
||||
BlockUtil.register(blockOreFactory, BlockOreFactory.TheItemBlock.class);
|
||||
|
||||
blockColoredLamp = new BlockColoredLamp(false);
|
||||
BlockUtil.register(blockColoredLamp, BlockColoredLamp.TheItemBlock.class);
|
||||
blockColoredLampOn = new BlockColoredLamp(true);
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package ellpeck.actuallyadditions.blocks.multi;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public interface IMultiBlock{
|
||||
|
||||
/**
|
||||
* @return The types of Block the Multiblock can contain
|
||||
*/
|
||||
Block[] getNeededBlocks();
|
||||
|
||||
/**
|
||||
* @return The Core TileEntity storing the MultiBlock's Data
|
||||
*/
|
||||
TileEntity getCore();
|
||||
|
||||
/**
|
||||
* @return The horizontal size of the MultiBlock
|
||||
*/
|
||||
int getSizeHor();
|
||||
|
||||
/**
|
||||
* @return The vertical size of the MultiBlock
|
||||
*/
|
||||
int getSizeVer();
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
package ellpeck.actuallyadditions.blocks.multi;
|
||||
|
||||
import ellpeck.actuallyadditions.util.WorldPos;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MultiBlockHelper{
|
||||
|
||||
/**
|
||||
* Checks if a MultiBlock can be created and creates it
|
||||
* Made for rectangular MultiBlocks that don't need special Blocks in certain places
|
||||
* @param block The MultiBlock Part the method is getting called from
|
||||
* @return The Multiblock if it worked, or null if it didn't
|
||||
*/
|
||||
public static ArrayList<WorldPos> createMultiBlock(IMultiBlock block, World blockWorld, int blockX, int blockY, int blockZ){
|
||||
if(blockWorld.isRemote) return null;
|
||||
|
||||
ArrayList<WorldPos> blocks = new ArrayList<WorldPos>();
|
||||
|
||||
int maxX = 0;
|
||||
int minX = 0;
|
||||
int maxZ = 0;
|
||||
int minZ = 0;
|
||||
int maxY = 0;
|
||||
int minY = 0;
|
||||
|
||||
//Setting Min and Max Boundaries of the MultiBlock
|
||||
|
||||
//Horizontal X+ +1/-1 to prevent bigger MultiBlocks from working too
|
||||
for(int i = blockX; i < blockX+block.getSizeHor()+1; i++){
|
||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(i, blockY, blockZ))){
|
||||
//TODO To Fix the two MultiBlocks next to each other issue, try to take away the -1, check for more Blocks
|
||||
//TODO That could fail the thing and then, later, remove one Block and check if the size is correct still
|
||||
maxX = i-1;
|
||||
break;
|
||||
}
|
||||
else maxX = i;
|
||||
}
|
||||
|
||||
//Horizontal X-
|
||||
for(int i = blockX; i >= blockX-block.getSizeHor()-1; i--){
|
||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(i, blockY, blockZ))){
|
||||
minX = i+1;
|
||||
break;
|
||||
}
|
||||
else minX = i;
|
||||
}
|
||||
|
||||
//Horizontal Z+
|
||||
for(int i = blockZ; i < blockZ+block.getSizeHor()+1; i++){
|
||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, blockY, i))){
|
||||
maxZ = i-1;
|
||||
break;
|
||||
}
|
||||
else maxZ = i;
|
||||
}
|
||||
|
||||
//Horizontal Z-
|
||||
for(int i = blockZ; i >= blockZ-block.getSizeHor()-1; i--){
|
||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, blockY, i))){
|
||||
minZ = i+1;
|
||||
break;
|
||||
}
|
||||
else minZ = i;
|
||||
}
|
||||
|
||||
//Horizontal Y+
|
||||
for(int i = blockY; i < blockY+block.getSizeVer()+1; i++){
|
||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, i, blockZ))){
|
||||
maxY = i-1;
|
||||
break;
|
||||
}
|
||||
else maxY = i;
|
||||
}
|
||||
|
||||
//Horizontal Y-
|
||||
for(int i = blockY; i >= blockY-block.getSizeVer()-1; i--){
|
||||
if(!containsBlock(block.getNeededBlocks(), blockWorld.getBlock(blockX, i, blockZ))){
|
||||
minY = i+1;
|
||||
break;
|
||||
}
|
||||
else minY = i;
|
||||
}
|
||||
|
||||
boolean failedOnce = false;
|
||||
|
||||
//Actually getting the MultiBlock
|
||||
//For all of the coordinates gotten before, get the Blocks and store them in the list
|
||||
for(int x = minX; x <= maxX; x++){
|
||||
for(int y = minY; y <= maxY; y++){
|
||||
for(int z = minZ; z <= maxZ; z++){
|
||||
//Needs to be the exact size, not too small
|
||||
if(containsBlock(block.getNeededBlocks(), blockWorld.getBlock(x, y, z)) && maxX+1-minX == block.getSizeHor() && maxZ+1-minZ == block.getSizeHor() && maxY+1-minY == block.getSizeVer()){
|
||||
//Add the Block to the List to return
|
||||
blocks.add(new WorldPos(blockWorld, x, y, z));
|
||||
//Set the Block to MultiBlock-"State"
|
||||
blockWorld.setBlockMetadataWithNotify(x, y, z, 1, 2);
|
||||
}
|
||||
else{
|
||||
failedOnce = true;
|
||||
blockWorld.setBlockMetadataWithNotify(x, y, z, 0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Reset the Blocks if the Check failed at any point
|
||||
if(failedOnce){
|
||||
for(WorldPos aBlock : blocks){
|
||||
if(containsBlock(block.getNeededBlocks(), aBlock.getBlock())){
|
||||
aBlock.getWorld().setBlockMetadataWithNotify(aBlock.getX(), aBlock.getY(), aBlock.getZ(), 0, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return failedOnce ? null : blocks;
|
||||
}
|
||||
|
||||
private static boolean containsBlock(Block[] blocks, Block block){
|
||||
for(Block aBlock : blocks){
|
||||
if(aBlock.equals(block)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue