Filling thing, part 1

This commit is contained in:
Ellpeck 2016-11-05 15:36:16 +01:00
parent bb9a8c0512
commit 584f6bc034
4 changed files with 197 additions and 30 deletions

View file

@ -23,7 +23,7 @@ if(hasProperty('buildnumber')){
} }
minecraft { minecraft {
version = "1.10.2-12.18.2.2114" version = "1.10.2-12.18.2.2121"
runDir = "idea" runDir = "idea"
mappings = "snapshot_20160519" mappings = "snapshot_20160519"

View file

@ -184,6 +184,7 @@ public class CreativeTab extends CreativeTabs{
this.add(InitItems.itemBatteryQuadruple); this.add(InitItems.itemBatteryQuadruple);
this.add(InitItems.itemBatteryQuintuple); this.add(InitItems.itemBatteryQuintuple);
this.add(InitItems.itemTeleStaff); this.add(InitItems.itemTeleStaff);
this.add(InitItems.itemFillingWand);
this.add(InitItems.itemGrowthRing); this.add(InitItems.itemGrowthRing);
this.add(InitItems.itemMagnetRing); this.add(InitItems.itemMagnetRing);

View file

@ -36,7 +36,6 @@ import net.minecraft.tileentity.TileEntityChest;
public final class InitItems{ public final class InitItems{
public static Item itemBooklet; public static Item itemBooklet;
public static Item itemFertilizer; public static Item itemFertilizer;
public static Item itemMisc; public static Item itemMisc;
public static Item itemFoods; public static Item itemFoods;
@ -47,57 +46,44 @@ public final class InitItems{
public static Item itemSolidifiedExperience; public static Item itemSolidifiedExperience;
public static Item itemLeafBlower; public static Item itemLeafBlower;
public static Item itemLeafBlowerAdvanced; public static Item itemLeafBlowerAdvanced;
public static Item itemPotionRing; public static Item itemPotionRing;
public static Item itemPotionRingAdvanced; public static Item itemPotionRingAdvanced;
public static Item itemPickaxeEmerald; public static Item itemPickaxeEmerald;
public static Item itemAxeEmerald; public static Item itemAxeEmerald;
public static Item itemShovelEmerald; public static Item itemShovelEmerald;
public static Item itemSwordEmerald; public static Item itemSwordEmerald;
public static Item itemHoeEmerald; public static Item itemHoeEmerald;
public static Item itemHelmEmerald; public static Item itemHelmEmerald;
public static Item itemChestEmerald; public static Item itemChestEmerald;
public static Item itemPantsEmerald; public static Item itemPantsEmerald;
public static Item itemBootsEmerald; public static Item itemBootsEmerald;
public static Item itemPickaxeObsidian; public static Item itemPickaxeObsidian;
public static Item itemAxeObsidian; public static Item itemAxeObsidian;
public static Item itemShovelObsidian; public static Item itemShovelObsidian;
public static Item itemSwordObsidian; public static Item itemSwordObsidian;
public static Item itemHoeObsidian; public static Item itemHoeObsidian;
public static Item itemPickaxeQuartz; public static Item itemPickaxeQuartz;
public static Item itemAxeQuartz; public static Item itemAxeQuartz;
public static Item itemShovelQuartz; public static Item itemShovelQuartz;
public static Item itemSwordQuartz; public static Item itemSwordQuartz;
public static Item itemHoeQuartz; public static Item itemHoeQuartz;
public static Item itemHelmObsidian; public static Item itemHelmObsidian;
public static Item itemChestObsidian; public static Item itemChestObsidian;
public static Item itemPantsObsidian; public static Item itemPantsObsidian;
public static Item itemBootsObsidian; public static Item itemBootsObsidian;
public static Item itemHelmQuartz; public static Item itemHelmQuartz;
public static Item itemChestQuartz; public static Item itemChestQuartz;
public static Item itemPantsQuartz; public static Item itemPantsQuartz;
public static Item itemBootsQuartz; public static Item itemBootsQuartz;
public static Item itemHairyBall; public static Item itemHairyBall;
public static Item itemRiceSeed; public static Item itemRiceSeed;
public static Item itemCanolaSeed; public static Item itemCanolaSeed;
public static Item itemFlaxSeed; public static Item itemFlaxSeed;
public static Item itemCoffeeSeed; public static Item itemCoffeeSeed;
public static Item itemResonantRice; public static Item itemResonantRice;
public static Item itemPhantomConnector; public static Item itemPhantomConnector;
public static Item itemCoffeeBean; public static Item itemCoffeeBean;
public static Item itemCoffee; public static Item itemCoffee;
public static Item woodenPaxel; public static Item woodenPaxel;
public static Item stonePaxel; public static Item stonePaxel;
public static Item ironPaxel; public static Item ironPaxel;
@ -106,7 +92,6 @@ public final class InitItems{
public static Item emeraldPaxel; public static Item emeraldPaxel;
public static Item obsidianPaxel; public static Item obsidianPaxel;
public static Item quartzPaxel; public static Item quartzPaxel;
public static Item itemDrill; public static Item itemDrill;
public static Item itemDrillUpgradeSpeed; public static Item itemDrillUpgradeSpeed;
public static Item itemDrillUpgradeSpeedII; public static Item itemDrillUpgradeSpeedII;
@ -117,27 +102,21 @@ public final class InitItems{
public static Item itemDrillUpgradeThreeByThree; public static Item itemDrillUpgradeThreeByThree;
public static Item itemDrillUpgradeFiveByFive; public static Item itemDrillUpgradeFiveByFive;
public static Item itemDrillUpgradeBlockPlacing; public static Item itemDrillUpgradeBlockPlacing;
public static Item itemBattery; public static Item itemBattery;
public static Item itemBatteryDouble; public static Item itemBatteryDouble;
public static Item itemBatteryTriple; public static Item itemBatteryTriple;
public static Item itemBatteryQuadruple; public static Item itemBatteryQuadruple;
public static Item itemBatteryQuintuple; public static Item itemBatteryQuintuple;
public static Item itemTeleStaff; public static Item itemTeleStaff;
public static Item itemWingsOfTheBats; public static Item itemWingsOfTheBats;
public static Item itemGrowthRing; public static Item itemGrowthRing;
public static Item itemMagnetRing; public static Item itemMagnetRing;
public static Item itemWaterRemovalRing; public static Item itemWaterRemovalRing;
public static Item itemChestToCrateUpgrade; public static Item itemChestToCrateUpgrade;
public static Item itemSmallToMediumCrateUpgrade; public static Item itemSmallToMediumCrateUpgrade;
public static Item itemMediumToLargeCrateUpgrade; public static Item itemMediumToLargeCrateUpgrade;
public static Item itemCrateKeeper; public static Item itemCrateKeeper;
public static Item itemSpawnerChanger; public static Item itemSpawnerChanger;
public static Item itemLaserWrench; public static Item itemLaserWrench;
public static Item itemCrystal; public static Item itemCrystal;
public static Item itemCrystalEmpowered; public static Item itemCrystalEmpowered;
@ -147,7 +126,6 @@ public final class InitItems{
public static Item itemMoreDamageLens; public static Item itemMoreDamageLens;
public static Item itemDisenchantingLens; public static Item itemDisenchantingLens;
public static Item itemMiningLens; public static Item itemMiningLens;
public static Item itemPickaxeCrystalRed; public static Item itemPickaxeCrystalRed;
public static Item itemAxeCrystalRed; public static Item itemAxeCrystalRed;
public static Item itemShovelCrystalRed; public static Item itemShovelCrystalRed;
@ -158,7 +136,6 @@ public final class InitItems{
public static Item itemPantsCrystalRed; public static Item itemPantsCrystalRed;
public static Item itemBootsCrystalRed; public static Item itemBootsCrystalRed;
public static Item itemPaxelCrystalRed; public static Item itemPaxelCrystalRed;
public static Item itemPickaxeCrystalBlue; public static Item itemPickaxeCrystalBlue;
public static Item itemAxeCrystalBlue; public static Item itemAxeCrystalBlue;
public static Item itemShovelCrystalBlue; public static Item itemShovelCrystalBlue;
@ -169,7 +146,6 @@ public final class InitItems{
public static Item itemPantsCrystalBlue; public static Item itemPantsCrystalBlue;
public static Item itemBootsCrystalBlue; public static Item itemBootsCrystalBlue;
public static Item itemPaxelCrystalBlue; public static Item itemPaxelCrystalBlue;
public static Item itemPickaxeCrystalLightBlue; public static Item itemPickaxeCrystalLightBlue;
public static Item itemAxeCrystalLightBlue; public static Item itemAxeCrystalLightBlue;
public static Item itemShovelCrystalLightBlue; public static Item itemShovelCrystalLightBlue;
@ -180,7 +156,6 @@ public final class InitItems{
public static Item itemPantsCrystalLightBlue; public static Item itemPantsCrystalLightBlue;
public static Item itemBootsCrystalLightBlue; public static Item itemBootsCrystalLightBlue;
public static Item itemPaxelCrystalLightBlue; public static Item itemPaxelCrystalLightBlue;
public static Item itemPickaxeCrystalBlack; public static Item itemPickaxeCrystalBlack;
public static Item itemAxeCrystalBlack; public static Item itemAxeCrystalBlack;
public static Item itemShovelCrystalBlack; public static Item itemShovelCrystalBlack;
@ -191,7 +166,6 @@ public final class InitItems{
public static Item itemPantsCrystalBlack; public static Item itemPantsCrystalBlack;
public static Item itemBootsCrystalBlack; public static Item itemBootsCrystalBlack;
public static Item itemPaxelCrystalBlack; public static Item itemPaxelCrystalBlack;
public static Item itemPickaxeCrystalGreen; public static Item itemPickaxeCrystalGreen;
public static Item itemAxeCrystalGreen; public static Item itemAxeCrystalGreen;
public static Item itemShovelCrystalGreen; public static Item itemShovelCrystalGreen;
@ -202,7 +176,6 @@ public final class InitItems{
public static Item itemPantsCrystalGreen; public static Item itemPantsCrystalGreen;
public static Item itemBootsCrystalGreen; public static Item itemBootsCrystalGreen;
public static Item itemPaxelCrystalGreen; public static Item itemPaxelCrystalGreen;
public static Item itemPickaxeCrystalWhite; public static Item itemPickaxeCrystalWhite;
public static Item itemAxeCrystalWhite; public static Item itemAxeCrystalWhite;
public static Item itemShovelCrystalWhite; public static Item itemShovelCrystalWhite;
@ -213,18 +186,18 @@ public final class InitItems{
public static Item itemPantsCrystalWhite; public static Item itemPantsCrystalWhite;
public static Item itemBootsCrystalWhite; public static Item itemBootsCrystalWhite;
public static Item itemPaxelCrystalWhite; public static Item itemPaxelCrystalWhite;
public static Item itemWaterBowl; public static Item itemWaterBowl;
public static Item itemFilter; public static Item itemFilter;
public static Item itemPlayerProbe; public static Item itemPlayerProbe;
public static Item itemWorm; public static Item itemWorm;
public static Item itemBag; public static Item itemBag;
public static Item itemVoidBag; public static Item itemVoidBag;
public static Item itemFillingWand;
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Initializing Items..."); ModUtil.LOGGER.info("Initializing Items...");
itemFillingWand = new ItemFillingWand("itemFillingWand");
itemBag = new ItemBag("itemBag", false); itemBag = new ItemBag("itemBag", false);
itemVoidBag = new ItemBag("itemVoidBag", true); itemVoidBag = new ItemBag("itemVoidBag", true);
itemWorm = new ItemWorm("itemWorm"); itemWorm = new ItemWorm("itemWorm");

View file

@ -0,0 +1,193 @@
/*
* This file ("ItemFillingWand.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class ItemFillingWand extends ItemEnergy{
public ItemFillingWand(String name){
super(500000, 1000, name);
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
if(player.getItemInUseCount() <= 0){
if(player.isSneaking()){
IBlockState state = world.getBlockState(pos);
saveBlock(state, stack);
return EnumActionResult.SUCCESS;
}
else if(loadBlock(stack) != null){
if(!stack.hasTagCompound()){
stack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound compound = stack.getTagCompound();
if(compound.getInteger("CurrX") == 0 && compound.getInteger("CurrY") == 0 && compound.getInteger("CurrZ") == 0){
compound.setInteger("FirstX", pos.getX());
compound.setInteger("FirstY", pos.getY());
compound.setInteger("FirstZ", pos.getZ());
player.setActiveHand(hand);
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entity, int timeLeft){
boolean clear = true;
if(entity instanceof EntityPlayer){
RayTraceResult result = WorldUtil.getNearestBlockWithDefaultReachDistance(world, (EntityPlayer)entity);
if(result != null && result.getBlockPos() != null){
if(!stack.hasTagCompound()){
stack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound compound = stack.getTagCompound();
BlockPos pos = result.getBlockPos();
compound.setInteger("SecondX", pos.getX());
compound.setInteger("SecondY", pos.getY());
compound.setInteger("SecondZ", pos.getZ());
clear = false;
}
}
if(clear){
ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ");
}
super.onPlayerStoppedUsing(stack, world, entity, timeLeft);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){
super.onUpdate(stack, world, entity, itemSlot, isSelected);
boolean shouldClear = false;
if(isSelected){
if(entity instanceof EntityPlayer && stack.hasTagCompound()){
NBTTagCompound compound = stack.getTagCompound();
BlockPos firstPos = new BlockPos(compound.getInteger("FirstX"), compound.getInteger("FirstY"), compound.getInteger("FirstZ"));
BlockPos secondPos = new BlockPos(compound.getInteger("SecondX"), compound.getInteger("SecondY"), compound.getInteger("SecondZ"));
if(!BlockPos.ORIGIN.equals(firstPos) && !BlockPos.ORIGIN.equals(secondPos)){
IBlockState replaceState = loadBlock(stack);
if(replaceState != null){
int lowestX = Math.min(firstPos.getX(), secondPos.getX());
int lowestY = Math.min(firstPos.getY(), secondPos.getY());
int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ());
int currX = compound.getInteger("CurrX");
int currY = compound.getInteger("CurrY");
int currZ = compound.getInteger("CurrZ");
BlockPos pos = new BlockPos(lowestX+currX, lowestY+currY, lowestZ+currZ);
IBlockState state = world.getBlockState(pos);
if(state.getBlock().isReplaceable(world, pos) && replaceState.getBlock().canPlaceBlockAt(world, pos)){
world.setBlockState(pos, replaceState, 2);
if(!ConfigBoolValues.LESS_SOUND.isEnabled()){
SoundType sound = replaceState.getBlock().getSoundType(replaceState, world, pos, entity);
world.playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume()+1.0F)/2.0F, sound.getPitch()*0.8F);
}
}
int distX = Math.abs(secondPos.getX()-firstPos.getX());
int distY = Math.abs(secondPos.getY()-firstPos.getY());
int distZ = Math.abs(secondPos.getZ()-firstPos.getZ());
currX++;
if(currX > distX){
currX = 0;
currY++;
if(currY > distY){
currY = 0;
currZ++;
if(currZ > distZ){
shouldClear = true;
}
}
}
compound.setInteger("CurrX", currX);
compound.setInteger("CurrY", currY);
compound.setInteger("CurrZ", currZ);
}
else{
shouldClear = true;
}
}
}
}
else{
shouldClear = true;
}
if(shouldClear){
ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ", "SecondX", "SecondY", "SecondZ", "CurrX", "CurrY", "CurrZ");
}
}
private static void saveBlock(IBlockState state, ItemStack stack){
if(!stack.hasTagCompound()){
stack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound compound = stack.getTagCompound();
Block block = state.getBlock();
compound.setString("Block", block.getRegistryName().toString());
compound.setInteger("Meta", block.getMetaFromState(state));
}
private static IBlockState loadBlock(ItemStack stack){
if(stack.hasTagCompound()){
NBTTagCompound compound = stack.getTagCompound();
String blockName = compound.getString("Block");
int meta = compound.getInteger("Meta");
Block block = Block.getBlockFromName(blockName);
if(block != null){
return block.getStateFromMeta(meta);
}
}
return null;
}
@Override
public int getMaxItemUseDuration(ItemStack stack){
return Integer.MAX_VALUE;
}
}