-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Added AbstractModContainerBlock, AbstractModTileEntity. -Added getUpateURL() to IMod.\n-Renamed getVerisionURL to getVersionURL in IMod. -Added readFromNBT() and writeToNBT() methods to ICoords/Coords class. -VersionChecker now first attempts to use the Forge update.json to track versions.
- Loading branch information
Showing
12 changed files
with
341 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
GottschCore1.12.2/src/com/someguyssoftware/gottschcore/block/AbstractModContainerBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* | ||
*/ | ||
package com.someguyssoftware.gottschcore.block; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.block.ITileEntityProvider; | ||
import net.minecraft.block.material.MapColor; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.enchantment.EnchantmentHelper; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.init.Enchantments; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.stats.StatList; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.EnumBlockRenderType; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.IWorldNameable; | ||
import net.minecraft.world.World; | ||
|
||
/** | ||
* This class replaces BlockContainer so that it can extend ModBlock | ||
* @author Mark Gottschling onJan 2, 2018 | ||
* | ||
*/ | ||
public abstract class AbstractModContainerBlock extends ModBlock implements ITileEntityProvider { | ||
|
||
/** | ||
* | ||
* @param modID | ||
* @param name | ||
* @param material | ||
*/ | ||
public AbstractModContainerBlock(String modID, String name, Material material) { | ||
this(modID, name, material, material.getMaterialMapColor()); | ||
} | ||
|
||
/** | ||
* | ||
* @param modID | ||
* @param name | ||
* @param material | ||
* @param mapColor | ||
*/ | ||
public AbstractModContainerBlock(String modID, String name, Material material, MapColor mapColor) { | ||
super(modID, name, material, mapColor); | ||
this.hasTileEntity = true; | ||
} | ||
|
||
/** | ||
* | ||
* @param worldIn | ||
* @param pos | ||
* @param facing | ||
* @return | ||
*/ | ||
protected boolean isInvalidNeighbor(World worldIn, BlockPos pos, EnumFacing facing) { | ||
return worldIn.getBlockState(pos.offset(facing)).getMaterial() == Material.CACTUS; | ||
} | ||
|
||
/** | ||
* | ||
* @param worldIn | ||
* @param pos | ||
* @return | ||
*/ | ||
protected boolean hasInvalidNeighbor(World worldIn, BlockPos pos) { | ||
return this.isInvalidNeighbor(worldIn, pos, EnumFacing.NORTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.SOUTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.WEST) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.EAST); | ||
} | ||
|
||
/** | ||
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only, | ||
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering. | ||
* Since this class is abstract, default to no rendering. | ||
*/ | ||
public EnumBlockRenderType getRenderType(IBlockState state) { | ||
return EnumBlockRenderType.INVISIBLE; | ||
} | ||
|
||
/** | ||
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated | ||
*/ | ||
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { | ||
super.breakBlock(worldIn, pos, state); | ||
worldIn.removeTileEntity(pos); | ||
} | ||
|
||
/** | ||
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via | ||
* Block.removedByPlayer | ||
*/ | ||
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) { | ||
if (te instanceof IWorldNameable && ((IWorldNameable)te).hasCustomName()) { | ||
player.addStat(StatList.getBlockStats(this)); | ||
player.addExhaustion(0.005F); | ||
|
||
if (worldIn.isRemote) { | ||
return; | ||
} | ||
|
||
int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack); | ||
Item item = this.getItemDropped(state, worldIn.rand, i); | ||
|
||
if (item == Items.AIR) { | ||
return; | ||
} | ||
|
||
ItemStack itemstack = new ItemStack(item, this.quantityDropped(worldIn.rand)); | ||
itemstack.setStackDisplayName(((IWorldNameable)te).getName()); | ||
spawnAsEntity(worldIn, pos, itemstack); | ||
} | ||
else { | ||
super.harvestBlock(worldIn, player, pos, state, (TileEntity)null, stack); | ||
} | ||
} | ||
|
||
/** | ||
* Called on server when World#addBlockEvent is called. If server returns true, then also called on the client. On | ||
* the Server, this may perform additional changes to the world, like pistons replacing the block with an extended | ||
* base. On the client, the update may involve replacing tile entities or effects such as sounds or particles | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
@Override | ||
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) { | ||
super.eventReceived(state, worldIn, pos, id, param); | ||
TileEntity tileentity = worldIn.getTileEntity(pos); | ||
return tileentity == null ? false : tileentity.receiveClientEvent(id, param); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
GottschCore1.12.2/src/com/someguyssoftware/gottschcore/tileentity/AbstractModTileEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* | ||
*/ | ||
package com.someguyssoftware.gottschcore.tileentity; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.network.NetworkManager; | ||
import net.minecraft.network.play.server.SPacketUpdateTileEntity; | ||
import net.minecraft.tileentity.TileEntity; | ||
|
||
/** | ||
* @author Mark Gottschling onJan 3, 2018 | ||
* | ||
*/ | ||
public abstract class AbstractModTileEntity extends TileEntity { | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
@Nullable | ||
public SPacketUpdateTileEntity getUpdatePacket() { | ||
NBTTagCompound nbtTagCompound = new NBTTagCompound(); | ||
writeToNBT(nbtTagCompound); | ||
int metadata = getBlockMetadata(); | ||
return new SPacketUpdateTileEntity(this.pos, metadata, nbtTagCompound); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
@Override | ||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { | ||
readFromNBT(pkt.getNbtCompound()); | ||
} | ||
|
||
/* Creates a tag containing the TileEntity information, used by vanilla to transmit from server to client | ||
*/ | ||
@Override | ||
public NBTTagCompound getUpdateTag() { | ||
NBTTagCompound nbtTagCompound = new NBTTagCompound(); | ||
writeToNBT(nbtTagCompound); | ||
return nbtTagCompound; | ||
} | ||
|
||
/* Populates this TileEntity with information from the tag, used by vanilla to transmit from server to client | ||
*/ | ||
@Override | ||
public void handleUpdateTag(NBTTagCompound tag) { | ||
this.readFromNBT(tag); | ||
} | ||
} |
Oops, something went wrong.