Bumped mappings, deprecated some base classes (for now), ported remaining

This commit is contained in:
Michael 2020-09-07 18:43:02 +01:00
parent 40d27de0f5
commit aa015521bc
No known key found for this signature in database
GPG key ID: 971C5B254742488F
11 changed files with 401 additions and 424 deletions

View file

@ -1,10 +1,8 @@
buildscript { buildscript {
repositories { repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter() jcenter()
maven { mavenCentral()
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
} }
dependencies { dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
@ -16,30 +14,40 @@ apply plugin: 'eclipse'
apply plugin: 'idea' apply plugin: 'idea'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
version = "2.0.0" version = mod_version
group = "de.ellpeck.actuallyadditions" group = "de.ellpeck.actuallyadditions"
archivesBaseName = "ActuallyAdditions-1.15.2" archivesBaseName = "actuallyadditions-${mc_version}"
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
minecraft { minecraft {
mappings channel: "stable", version: "60-1.15" mappings channel: "snapshot", version: mcp_version
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
runs { runs {
client = { client {
properties 'forge.logging.markers': '' properties 'forge.logging.markers': ''
properties 'forge.logging.console.level': 'debug' properties 'forge.logging.console.level': 'debug'
workingDirectory project.file('run').canonicalPath workingDirectory project.file('run')
mods {
actuallyadditions {
source sourceSets.main source sourceSets.main
} }
server = { }
}
server {
properties 'forge.logging.markers': '' properties 'forge.logging.markers': ''
properties 'forge.logging.console.level': 'debug' properties 'forge.logging.console.level': 'debug'
workingDirectory project.file('run/server').canonicalPath workingDirectory project.file('run')
mods {
actuallyadditions {
source sourceSets.main source sourceSets.main
} }
data = { }
workingDirectory project.file("run/data").canonicalPath }
args "--mod", "actuallyadditions", "--all", "--output", "\"" + file("src/generated/resources").toString() + "\"", "--validate", "--existing", "\"" + sourceSets.main.resources.srcDirs[0] + "\"" data {
workingDirectory project.file('run')
args "--mod", "actuallyadditions", "--all", "--output", file('src/generated/resources/'), "--existing", "\"" + sourceSets.main.resources.srcDirs[0] + "\""
mods { mods {
actuallyadditions { actuallyadditions {
source sourceSets.main source sourceSets.main
@ -51,19 +59,18 @@ minecraft {
repositories { repositories {
maven { maven {
// location of the maven that hosts JEI files name = "Progwml6 maven / JEI Maven"
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/" url = "https://dvs1.progwml6.com/files/maven/"
} }
maven { maven {
// location of a maven mirror for JEI files, as a fallback name = "ModMaven / JEI Mirror"
name = "ModMaven"
url = "https://modmaven.k-4u.nl" url = "https://modmaven.k-4u.nl"
} }
} }
dependencies { dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}" minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
// compile against the JEI API but do not include it at runtime // compile against the JEI API but do not include it at runtime
compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api")
// at runtime, use the full JEI jar // at runtime, use the full JEI jar
@ -74,7 +81,7 @@ jar {
manifest { manifest {
attributes(["Specification-Title": "actuallyadditions", attributes(["Specification-Title": "actuallyadditions",
"Specification-Vendor": "Ellpeck", "Specification-Vendor": "Ellpeck",
"Specification-Version": "24.0", "Specification-Version": mod_version,
"Implementation-Title": project.name, "Implementation-Title": project.name,
"Implementation-Version": "${version}", "Implementation-Version": "${version}",
"Implementation-Vendor" :"Ellpeck", "Implementation-Vendor" :"Ellpeck",

View file

@ -3,6 +3,9 @@
org.gradle.jvmargs=-Xmx3G org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false org.gradle.daemon=false
mod_version=2.0
mc_version=1.15.2 mc_version=1.15.2
forge_version=31.2.0 mcp_version=20200514-1.15.1
forge_version=31.2.36
jei_version=6.0.3.15 jei_version=6.0.3.15

View file

@ -1,48 +1,51 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; //package de.ellpeck.actuallyadditions.mod.blocks.base;
//
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; //import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel; //import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; //import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import net.minecraft.block.Block; //import net.minecraft.block.Block;
import net.minecraft.block.material.Material; //import net.minecraft.block.material.Material;
import net.minecraft.item.EnumRarity; //import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; //import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IRarity; //import net.minecraft.item.Rarity;
//import net.minecraftforge.common.IRarity;
public class BlockBase extends Block implements ItemBlockBase.ICustomRarity, IHasModel { //
//public class BlockBase extends Block implements ItemBlockBase.ICustomRarity, IHasModel {
private final String name; //
// private final String name;
public BlockBase(Material material, String name) { //
super(material); // public BlockBase(Material material, String name) {
this.name = name; // super(material);
// this.name = name;
this.register(); //
} // this.register();
// }
private void register() { //
ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); // private void register() {
} // ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
// }
protected String getBaseName() { //
return this.name; // protected String getBaseName() {
} // return this.name;
// }
protected ItemBlockBase getItemBlock() { //
return new ItemBlockBase(this); // protected ItemBlockBase getItemBlock() {
} // return new ItemBlockBase(this);
// }
public boolean shouldAddCreative() { //
return true; // public boolean shouldAddCreative() {
} // return true;
// }
@Override //
public void registerRendering() { // @Override
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory"); // public void registerRendering() {
} // ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
// }
@Override //
public IRarity getRarity(ItemStack stack) { //
return EnumRarity.COMMON; //
} // @Override
} // public Rarity getRarity(ItemStack stack) {
// return EnumRarity.COMMON;
// }
//}

View file

@ -1,47 +1,33 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; package de.ellpeck.actuallyadditions.mod.blocks.base;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import net.minecraft.block.BushBlock;
import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import net.minecraft.block.BlockBush;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
public class BlockBushBase extends BlockBush implements ItemBlockBase.ICustomRarity, IHasModel { public class BlockBushBase extends BushBlock {
public BlockBushBase(Properties properties) {
private final String name; super(properties.sound(SoundType.PLANT));
// this.register();
public BlockBushBase(String name) {
this.name = name;
this.setSoundType(SoundType.PLANT);
this.register();
} }
private void register() { // private void register() {
ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); // ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
} // }
protected String getBaseName() { // protected ItemBlockBase getItemBlock() {
return this.name; // return new ItemBlockBase(this);
} // }
protected ItemBlockBase getItemBlock() {
return new ItemBlockBase(this);
}
public boolean shouldAddCreative() { public boolean shouldAddCreative() {
return true; return true;
} }
@Override // @Override
public void registerRendering() { // public void registerRendering() {
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory"); // ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
} // }
@Override // @Override
public EnumRarity getRarity(ItemStack stack) { // public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.COMMON; // return EnumRarity.COMMON;
} // }
} }

View file

@ -1,79 +1,63 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; package de.ellpeck.actuallyadditions.mod.blocks.base;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block; import net.minecraft.block.*;
import net.minecraft.block.BlockContainer; import net.minecraft.entity.LivingEntity;
import net.minecraft.block.material.Material; import net.minecraft.entity.MoverType;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.fluid.IFluidState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.Hand;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.Style; import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.IBlockAccess; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidTank; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.templates.FluidTank;
public abstract class BlockContainerBase extends BlockContainer implements ItemBlockBase.ICustomRarity, IHasModel { import javax.annotation.Nullable;
import java.util.Random;
private final String name; public abstract class BlockContainerBase extends ContainerBlock {
public BlockContainerBase(Material material, String name) { public BlockContainerBase(Properties properties) {
super(material); super(properties);
this.name = name;
this.register(); // this.register();
} }
private void register() { // private void register() {
ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); // ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
} // }
protected String getBaseName() { // protected ItemBlockBase getItemBlock() {
return this.name; // return new ItemBlockBase(this);
} // }
protected ItemBlockBase getItemBlock() {
return new ItemBlockBase(this);
}
public boolean shouldAddCreative() { public boolean shouldAddCreative() {
return true; return true;
} }
@Override // @Override
public void registerRendering() { // public void registerRendering() {
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory"); // ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
} // }
//
@Override // @Override
public EnumRarity getRarity(ItemStack stack) { // public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.COMMON; // return EnumRarity.COMMON;
} // }
private void dropInventory(World world, BlockPos position) { private void dropInventory(World world, BlockPos position) {
if (!world.isRemote) { if (!world.isRemote) {
@ -89,22 +73,27 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
} }
} }
// todo: replace with native implementation
private void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, BlockPos pos) { private void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, BlockPos pos) {
ItemStack stack = tile.inv.getStackInSlot(i); ItemStack stack = tile.inv.getStackInSlot(i);
if (StackUtil.isValid(stack)) { if (StackUtil.isValid(stack)) {
float dX = world.rand.nextFloat() * 0.8F + 0.1F; float dX = world.rand.nextFloat() * 0.8F + 0.1F;
float dY = world.rand.nextFloat() * 0.8F + 0.1F; float dY = world.rand.nextFloat() * 0.8F + 0.1F;
float dZ = world.rand.nextFloat() * 0.8F + 0.1F; float dZ = world.rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, stack.copy()); ItemEntity entityItem = new ItemEntity(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, stack.copy());
float factor = 0.05F; float factor = 0.05F;
entityItem.motionX = world.rand.nextGaussian() * factor;
entityItem.motionY = world.rand.nextGaussian() * factor + 0.2F; entityItem.move(MoverType.SELF, new Vec3d(
entityItem.motionZ = world.rand.nextGaussian() * factor; world.rand.nextGaussian() * factor,
world.spawnEntity(entityItem); world.rand.nextGaussian() * factor + 0.2F,
world.rand.nextGaussian() * factor
));
world.addEntity(entityItem);
} }
} }
public boolean tryToggleRedstone(World world, BlockPos pos, EntityPlayer player) { public boolean tryToggleRedstone(World world, BlockPos pos, PlayerEntity player) {
ItemStack stack = player.getHeldItemMainhand(); ItemStack stack = player.getHeldItemMainhand();
if (StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemRedstoneTorchConfigurator) { if (StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemRedstoneTorchConfigurator) {
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
@ -122,7 +111,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
} }
@Override @Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random random) { public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!world.isRemote) { if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityBase) { if (tile instanceof TileEntityBase) {
@ -147,18 +136,18 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
} }
@Override @Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos otherPos) { public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) {
this.neighborsChangedCustom(worldIn, pos); super.onNeighborChange(state, world, pos, neighbor);
}
@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
super.onNeighborChange(world, pos, neighbor);
if (world instanceof World) { if (world instanceof World) {
this.neighborsChangedCustom((World) world, pos); this.neighborsChangedCustom((World) world, pos);
} }
} }
@Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
this.neighborsChangedCustom(worldIn, pos);
}
public void updateRedstoneState(World world, BlockPos pos) { public void updateRedstoneState(World world, BlockPos pos) {
if (!world.isRemote) { if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
@ -168,7 +157,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
boolean wasPowered = base.isRedstonePowered; boolean wasPowered = base.isRedstonePowered;
if (powered && !wasPowered) { if (powered && !wasPowered) {
if (base.respondsToPulses()) { if (base.respondsToPulses()) {
world.scheduleUpdate(pos, this, this.tickRate(world)); world.getPendingBlockTicks().scheduleTick(pos, this, this.tickRate(world));
} }
base.setRedstonePowered(true); base.setRedstonePowered(true);
} else if (!powered && wasPowered) { } else if (!powered && wasPowered) {
@ -178,114 +167,115 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
} }
} }
protected boolean tryUseItemOnTank(EntityPlayer player, EnumHand hand, FluidTank tank) { protected boolean tryUseItemOnTank(PlayerEntity player, Hand hand, FluidTank tank) {
ItemStack heldItem = player.getHeldItem(hand); ItemStack heldItem = player.getHeldItem(hand);
return StackUtil.isValid(heldItem) && FluidUtil.interactWithFluidHandler(player, hand, tank); return StackUtil.isValid(heldItem) && FluidUtil.interactWithFluidHandler(player, hand, tank);
} }
@Override @Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) { public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean isMoving) {
this.updateRedstoneState(world, pos); this.updateRedstoneState(world, pos);
} }
@Override @Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) { public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
if (stack.hasTagCompound()) { if (stack.hasTag()) {
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityBase) { if (tile instanceof TileEntityBase) {
TileEntityBase base = (TileEntityBase) tile; TileEntityBase base = (TileEntityBase) tile;
NBTTagCompound compound = stack.getTagCompound().getCompoundTag("Data"); CompoundNBT compound = stack.getOrCreateTag().getCompound("Data");
if (compound != null) {
base.readSyncableNBT(compound, TileEntityBase.NBTType.SAVE_BLOCK); base.readSyncableNBT(compound, TileEntityBase.NBTType.SAVE_BLOCK);
} }
} }
} }
}
@Override @Override
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) { public void onBlockHarvested(World world, BlockPos pos, BlockState state, PlayerEntity player) {
if (!player.capabilities.isCreativeMode) { if (!player.isCreative()) {
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityBase && ((TileEntityBase) tile).stopFromDropping) { if (tile instanceof TileEntityBase && ((TileEntityBase) tile).stopFromDropping) {
player.sendMessage(new TextComponentTranslation("info." + ActuallyAdditions.MODID + ".machineBroke").setStyle(new Style().setColor(TextFormatting.RED))); player.sendMessage(new TranslationTextComponent("info." + ActuallyAdditions.MODID + ".machineBroke").setStyle(new Style().setColor(TextFormatting.RED)));
} }
} }
} }
@Override @Override
public boolean hasComparatorInputOverride(IBlockState state) { public boolean hasComparatorInputOverride(BlockState state) {
return true; return true;
} }
@Override @Override
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) { public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityBase) { return ((TileEntityBase) tile).getComparatorStrength(); } if (tile instanceof TileEntityBase) { return ((TileEntityBase) tile).getComparatorStrength(); }
return 0; return 0;
} }
// todo: come back to this. It think it's goal is to keep data on the dropped item... I know
// how to do this but I need to make sure I do it right.
// @Override
// public void spawnAdditionalDrops(BlockState state, World world, BlockPos pos, ItemStack stack) {
// TileEntity tile = world.getTileEntity(pos);
// if (tile instanceof TileEntityBase) {
// TileEntityBase base = (TileEntityBase) tile;
// if (!base.stopFromDropping) {
// CompoundNBT data = new CompoundNBT();
// base.writeSyncableNBT(data, TileEntityBase.NBTType.SAVE_BLOCK);
//
// //Remove unnecessarily saved default values to avoid unstackability
// List<String> keysToRemove = new ArrayList<>();
// for (String key : data.getKeySet()) {
// NBTBase tag = data.getTag(key);
// //Remove only ints because they are the most common ones
// //Add else if below here to remove more types
// if (tag instanceof NBTTagInt) {
// if (((NBTTagInt) tag).getInt() == 0) {
// keysToRemove.add(key);
// }
// }
// }
// for (String key : keysToRemove) {
// data.remove(key);
// }
//
// ItemStack stack = new ItemStack(this.getItemDropped(state, tile.getWorld().rand, fortune), 1, this.damageDropped(state));
// if (!data.isEmpty()) {
// stack.setTagCompound(new NBTTagCompound());
// stack.getTagCompound().setTag("Data", data);
// }
//
// drops.add(stack);
// }
// }
// }
@Override @Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid) {
TileEntity tile = world.getTileEntity(pos); return willHarvest || super.removedByPlayer(state, world, pos, player, false, fluid);
if (tile instanceof TileEntityBase) {
TileEntityBase base = (TileEntityBase) tile;
if (!base.stopFromDropping) {
NBTTagCompound data = new NBTTagCompound();
base.writeSyncableNBT(data, TileEntityBase.NBTType.SAVE_BLOCK);
//Remove unnecessarily saved default values to avoid unstackability
List<String> keysToRemove = new ArrayList<>();
for (String key : data.getKeySet()) {
NBTBase tag = data.getTag(key);
//Remove only ints because they are the most common ones
//Add else if below here to remove more types
if (tag instanceof NBTTagInt) {
if (((NBTTagInt) tag).getInt() == 0) {
keysToRemove.add(key);
}
}
}
for (String key : keysToRemove) {
data.removeTag(key);
}
ItemStack stack = new ItemStack(this.getItemDropped(state, tile.getWorld().rand, fortune), 1, this.damageDropped(state));
if (!data.isEmpty()) {
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setTag("Data", data);
}
drops.add(stack);
}
} else {
super.getDrops(drops, world, pos, state, fortune);
}
} }
@Override @Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) {
return willHarvest || super.removedByPlayer(state, world, pos, player, false);
}
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack); super.harvestBlock(worldIn, player, pos, state, te, stack);
worldIn.setBlockToAir(pos); worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
} }
@Override @Override
public EnumBlockRenderType getRenderType(IBlockState state) { public BlockRenderType getRenderType(BlockState state) {
return EnumBlockRenderType.MODEL; return BlockRenderType.MODEL;
} }
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state) { public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving) {
if (this.shouldDropInventory(world, pos)) { // todo: this might not work with this sepecific state check
if (state != newState && this.shouldDropInventory(world, pos)) {
this.dropInventory(world, pos); this.dropInventory(world, pos);
} }
super.breakBlock(world, pos, state); super.onReplaced(state, world, pos, newState, isMoving);
} }
public boolean shouldDropInventory(World world, BlockPos pos) { public boolean shouldDropInventory(World world, BlockPos pos) {

View file

@ -1,55 +1,52 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; package de.ellpeck.actuallyadditions.mod.blocks.base;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.item.EnumRarity; import net.minecraft.fluid.FlowingFluid;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
public class BlockFluidFlowing extends BlockFluidClassic implements ItemBlockBase.ICustomRarity { @Deprecated
public class BlockFluidFlowing extends FlowingFluidBlock {
private final String name; // private final String name;
public BlockFluidFlowing(Fluid fluid, Material material, String unlocalizedName) { public BlockFluidFlowing(FlowingFluid fluid, Block.Properties builder) {
super(fluid, material); super(fluid, builder);
this.name = unlocalizedName; // this.name = unlocalizedName;
this.displacements.put(this, false); // todo: check this
// this.displacements.put(this, false);
this.register(); // this.register();
} }
private void register() { // private void register() {
ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); // ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
} // }
protected String getBaseName() { // protected String getBaseName() {
return this.name; // return this.name;
} // }
protected ItemBlockBase getItemBlock() { // protected ItemBlockBase getItemBlock() {
return new ItemBlockBase(this); // return new ItemBlockBase(this);
} // }
public boolean shouldAddCreative() { public boolean shouldAddCreative() {
return false; return false;
} }
@Override // todo: reeval canDisplay and displaceIfPossible
public boolean canDisplace(IBlockAccess world, BlockPos pos) { // @Override
return !world.getBlockState(pos).getMaterial().isLiquid() && super.canDisplace(world, pos); // public boolean canDisplace(IBlockAccess world, BlockPos pos) {
} // return !world.getBlockState(pos).getMaterial().isLiquid() && super.canDisplace(world, pos);
// }
@Override //
public boolean displaceIfPossible(World world, BlockPos pos) { // @Override
return !world.getBlockState(pos).getMaterial().isLiquid() && super.displaceIfPossible(world, pos); // public boolean displaceIfPossible(World world, BlockPos pos) {
} // return !world.getBlockState(pos).getMaterial().isLiquid() && super.displaceIfPossible(world, pos);
// }
@Override ////
public EnumRarity getRarity(ItemStack stack) { // @Override
return EnumRarity.EPIC; // public EnumRarity getRarity(ItemStack stack) {
} // return EnumRarity.EPIC;
// }
} }

View file

@ -10,92 +10,89 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; package de.ellpeck.actuallyadditions.mod.blocks.base;
import java.util.Random;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockState;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.CropsBlock;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.ActionResultType;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.NonNullList; import net.minecraft.util.IItemProvider;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.PlantType;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
public class BlockPlant extends BlockCrops implements ItemBlockBase.ICustomRarity, IHasModel { import java.util.List;
private final String name; public class BlockPlant extends CropsBlock {// implements ItemBlockBase.ICustomRarity, IHasModel {
private final int minDropAmount;
private final int addDropAmount; // private final String name;
private final int minDropAmount = 1;
private final int addDropAmount = 1;
public Item seedItem; public Item seedItem;
private Item returnItem; private Item returnItem;
private int returnMeta; private int returnMeta;
public BlockPlant(String name, int minDropAmount, int addDropAmount) { public BlockPlant(Properties properties) {
this.name = name; super(properties);
this.minDropAmount = minDropAmount; // this.name = name;
this.addDropAmount = addDropAmount; // this.minDropAmount = minDropAmount;
this.register(); // this.addDropAmount = addDropAmount;
// this.register();
} }
// todo: check what this is doing
public void doStuff(Item seedItem, Item returnItem, int returnMeta) { public void doStuff(Item seedItem, Item returnItem, int returnMeta) {
this.seedItem = seedItem; this.seedItem = seedItem;
this.returnItem = returnItem; this.returnItem = returnItem;
this.returnMeta = returnMeta; this.returnMeta = returnMeta;
} }
private void register() { // private void register() {
ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); // ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
} // }
protected String getBaseName() { // protected String getBaseName() {
return this.name; // return this.name;
} // }
protected ItemBlockBase getItemBlock() { // protected ItemBlockBase getItemBlock() {
return new ItemBlockBase(this); // return new ItemBlockBase(this);
} // }
public boolean shouldAddCreative() { public boolean shouldAddCreative() {
return false; return false;
} }
@Override // @Override
public void registerRendering() { // public void registerRendering() {
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory"); // ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
} // }
//
@Override @Override
public EnumRarity getRarity(ItemStack stack) { public PlantType getPlantType(IBlockReader world, BlockPos pos) {
return EnumRarity.RARE; return PlantType.Crop;
} }
//
// @Override
// public int damageDropped(IBlockState state) {
// return this.getMetaFromState(state) >= 7 ? this.returnMeta : 0;
// }
@Override @Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) { public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
return EnumPlantType.Crop; if (getAge(state) > 7) {
}
@Override
public int damageDropped(IBlockState state) {
return this.getMetaFromState(state) >= 7 ? this.returnMeta : 0;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (this.getMetaFromState(state) >= 7) {
if (!world.isRemote) { if (!world.isRemote) {
List<ItemStack> drops = getDrops(state, (ServerWorld) world, pos, null);
NonNullList<ItemStack> drops = NonNullList.create();
this.getDrops(drops, world, pos, state, 0);
boolean deductedSeedSize = false; boolean deductedSeedSize = false;
for (ItemStack drop : drops) { for (ItemStack drop : drops) {
if (StackUtil.isValid(drop)) { if (StackUtil.isValid(drop)) {
@ -109,31 +106,35 @@ public class BlockPlant extends BlockCrops implements ItemBlockBase.ICustomRarit
} }
} }
world.setBlockState(pos, this.getStateFromMeta(0)); world.setBlockState(pos, state.with(AGE, 0));
} }
return true;
return ActionResultType.SUCCESS;
} }
return false;
return super.onBlockActivated(state, world, pos, player, handIn, hit);
} }
@Override @Override
public Item getSeed() { protected IItemProvider getSeedsItem() {
return this.seedItem; return this.seedItem;
} }
@Override // todo: this is likely handled by loot tables now
public int quantityDropped(IBlockState state, int fortune, Random random) {
return this.getMetaFromState(state) >= 7 ? random.nextInt(this.addDropAmount) + this.minDropAmount : super.quantityDropped(state, fortune, random);
}
@Override // @Override
public Item getCrop() { // public int quantityDropped(IBlockState state, int fortune, Random random) {
return this.returnItem; // return this.getMetaFromState(state) >= 7 ? random.nextInt(this.addDropAmount) + this.minDropAmount : super.quantityDropped(state, fortune, random);
} // }
@Override // @Override
public Item getItemDropped(IBlockState state, Random rand, int par3) { // public Item getCrop() {
return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed(); // return this.returnItem;
} // }
// @Override
// public Item getItemDropped(IBlockState state, Random rand, int par3) {
// return this.getMetaFromState(state) >= 7 ? this.getCrop() : this.getSeed();
// }
} }

View file

@ -1,53 +1,57 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; //package de.ellpeck.actuallyadditions.mod.blocks.base;
//
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; //import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel; //import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; //import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import net.minecraft.block.Block; //import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs; //import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.IBlockState; //import net.minecraft.block.BlockState;
import net.minecraft.item.EnumRarity; //import net.minecraft.block.StairsBlock;
import net.minecraft.item.ItemStack; //import net.minecraft.block.state.IBlockState;
//import net.minecraft.item.EnumRarity;
public class BlockStair extends BlockStairs implements ItemBlockBase.ICustomRarity, IHasModel { //import net.minecraft.item.ItemStack;
//
private final String name; //@Deprecated
//public class BlockStair extends StairsBlock { //BlockStairs implements ItemBlockBase.ICustomRarity, IHasModel {
public BlockStair(Block block, String name) { //
this(block.getDefaultState(), name); //// private final String name;
} //
//// public BlockStair(Block block, String name) {
public BlockStair(IBlockState state, String name) { ////
super(state); //// this(block.getDefaultState(), name);
this.name = name; //// }
this.setLightOpacity(0); ////
//// public BlockStair(BlockState state) {
this.register(); ////// super(state);
} ////// this.name = name;
////// this.setLightOpacity(0);
private void register() { ////
ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative()); ////// this.register();
} //// }
//
protected String getBaseName() { //// private void register() {
return this.name; //// ItemUtil.registerBlock(this, this.getItemBlock(), this.getBaseName(), this.shouldAddCreative());
} //// }
//
protected ItemBlockBase getItemBlock() { //// protected String getBaseName() {
return new ItemBlockBase(this); //// return this.name;
} //// }
//
public boolean shouldAddCreative() { //// protected ItemBlockBase getItemBlock() {
return true; //// return new ItemBlockBase(this);
} //// }
//
@Override // public boolean shouldAddCreative() {
public void registerRendering() { // return true;
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory"); // }
} //
//// @Override
@Override //// public void registerRendering() {
public EnumRarity getRarity(ItemStack stack) { //// ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
return EnumRarity.COMMON; //// }
} //
} //// @Override
//// public EnumRarity getRarity(ItemStack stack) {
//// return EnumRarity.COMMON;
//// }
//}

View file

@ -1,41 +1,25 @@
package de.ellpeck.actuallyadditions.mod.blocks.base; package de.ellpeck.actuallyadditions.mod.blocks.base;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.Item;
import net.minecraftforge.common.IRarity;
public class ItemBlockBase extends ItemBlock { @Deprecated
public class ItemBlockBase extends BlockItem {
public ItemBlockBase(Block block) { public ItemBlockBase(Block block, Item.Properties properties) {
super(block); super(block, properties);
this.setHasSubtypes(false); // this.setHasSubtypes(false);
this.setMaxDamage(0); // this.setMaxDamage(0);
} }
@Override // @Override
public String getTranslationKey(ItemStack stack) { // public String getTranslationKey(ItemStack stack) {
return this.getTranslationKey(); // return this.getTranslationKey();
} // }
//
@Override // @Override
public int getMetadata(int damage) { // public int getMetadata(int damage) {
return damage; // return damage;
} // }
@Override
public IRarity getForgeRarity(ItemStack stack) {
if (this.block instanceof ICustomRarity) {
return ((ICustomRarity) this.block).getRarity(stack);
} else {
return Util.FALLBACK_RARITY;
}
}
public interface ICustomRarity {
IRarity getRarity(ItemStack stack);
}
} }

View file

@ -1,5 +1,6 @@
package de.ellpeck.actuallyadditions.mod.blocks.render; package de.ellpeck.actuallyadditions.mod.blocks.render;
@Deprecated
public interface IHasModel { public interface IHasModel {
public void registerRendering(); public void registerRendering();

View file

@ -6,6 +6,7 @@ import de.ellpeck.actuallyadditions.mod.util.VanillaPacketDispatcher;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.network.play.server.SPacketUpdateTileEntity;
@ -163,7 +164,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
}*/ }*/
} }
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
if (type != NBTType.SAVE_BLOCK) super.writeToNBT(compound); if (type != NBTType.SAVE_BLOCK) super.writeToNBT(compound);
if (type == NBTType.SAVE_TILE) { if (type == NBTType.SAVE_TILE) {
@ -177,7 +178,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable {
} }
} }
public void readSyncableNBT(NBTTagCompound compound, NBTType type) { public void readSyncableNBT(CompoundNBT compound, NBTType type) {
if (type != NBTType.SAVE_BLOCK) super.readFromNBT(compound); if (type != NBTType.SAVE_BLOCK) super.readFromNBT(compound);
if (type == NBTType.SAVE_TILE) { if (type == NBTType.SAVE_TILE) {