forked from Draconic-Inc/Draconic-Evolution
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bca300
commit bf5f0bc
Showing
9 changed files
with
219 additions
and
1 deletion.
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
84 changes: 84 additions & 0 deletions
84
...ain/java/com/brandon3055/draconicevolution/common/blocks/machine/DislocatorInhibitor.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,84 @@ | ||
package com.brandon3055.draconicevolution.common.blocks.machine; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.ITileEntityProvider; | ||
import net.minecraft.client.renderer.texture.IIconRegister; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.ChatComponentText; | ||
import net.minecraft.world.IBlockAccess; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.util.ForgeDirection; | ||
|
||
import com.brandon3055.draconicevolution.DraconicEvolution; | ||
import com.brandon3055.draconicevolution.common.ModBlocks; | ||
import com.brandon3055.draconicevolution.common.blocks.BlockDE; | ||
import com.brandon3055.draconicevolution.common.lib.References; | ||
import com.brandon3055.draconicevolution.common.lib.Strings; | ||
import com.brandon3055.draconicevolution.common.tileentities.TileDislocatorInhibitor; | ||
|
||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
|
||
public class DislocatorInhibitor extends BlockDE implements ITileEntityProvider { | ||
|
||
public DislocatorInhibitor() { | ||
this.setBlockName(Strings.dislocatorInhibitor); | ||
this.setCreativeTab(DraconicEvolution.tabBlocksItems); | ||
this.setStepSound(soundTypeStone); | ||
ModBlocks.register(this); | ||
} | ||
|
||
@Override | ||
public boolean isBlockSolid(IBlockAccess world, int x, int y, int z, int side) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hasTileEntity(int metadata) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public TileEntity createNewTileEntity(World worldIn, int meta) { | ||
return new TileDislocatorInhibitor(); | ||
} | ||
|
||
@Override | ||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float prx, | ||
float pry, float prz) { | ||
TileEntity tile = world.getTileEntity(x, y, z); | ||
if (tile != null) { | ||
if (tile instanceof TileDislocatorInhibitor te) { | ||
if (!player.isSneaking()) te.increaseRange(); | ||
else te.decreaseRange(); | ||
|
||
if (world.isRemote) player.addChatMessage(new ChatComponentText("Range: " + te.getRange())); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void breakBlock(World worldIn, int x, int y, int z, Block blockBroken, int meta) { | ||
TileEntity tile = worldIn.getTileEntity(x, y, z); | ||
if (tile != null) { | ||
if (tile instanceof TileDislocatorInhibitor) { | ||
((TileDislocatorInhibitor) tile).unregister(); | ||
} | ||
} | ||
|
||
super.breakBlock(worldIn, x, y, z, blockBroken, meta); | ||
} | ||
|
||
@SideOnly(Side.CLIENT) | ||
@Override | ||
public void registerBlockIcons(IIconRegister iconRegister) { | ||
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "inhibitor_block"); | ||
} | ||
} |
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
112 changes: 112 additions & 0 deletions
112
...n/java/com/brandon3055/draconicevolution/common/tileentities/TileDislocatorInhibitor.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,112 @@ | ||
package com.brandon3055.draconicevolution.common.tileentities; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
|
||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.network.NetworkManager; | ||
import net.minecraft.network.Packet; | ||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.world.World; | ||
|
||
public class TileDislocatorInhibitor extends TileEntity { | ||
|
||
public static final int MAXIMUM_RANGE = 16; | ||
public static final int MINIMUM_RANGE = 1; | ||
public static final HashMap<World, HashSet<TileDislocatorInhibitor>> inhibitors = new HashMap<>(); | ||
|
||
private boolean registered = false; | ||
private int range = 5; | ||
|
||
public static boolean isInInhibitorRange(World world, double x, double y, double z) { | ||
HashSet<TileDislocatorInhibitor> list = inhibitors.get(world); | ||
if (list == null) { | ||
return false; | ||
} | ||
for (TileDislocatorInhibitor inhibitor : list) { | ||
if (inhibitor.isInRange(x, y, z)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void updateEntity() { | ||
if (!registered) { | ||
HashSet<TileDislocatorInhibitor> map = inhibitors.computeIfAbsent(this.worldObj, k -> new HashSet<>()); | ||
map.add(this); | ||
registered = true; | ||
} | ||
} | ||
|
||
public void unregister() { | ||
if (inhibitors.containsKey(this.worldObj)) { | ||
HashSet<TileDislocatorInhibitor> list = inhibitors.get(this.worldObj); | ||
list.remove(this); | ||
if (list.isEmpty()) { | ||
inhibitors.remove(this.worldObj); | ||
} | ||
} | ||
} | ||
|
||
public int getRange() { | ||
return range; | ||
} | ||
|
||
public void setRange(int value) { | ||
if (value > MAXIMUM_RANGE) { | ||
value = MINIMUM_RANGE; | ||
} | ||
if (value < MINIMUM_RANGE) { | ||
value = MAXIMUM_RANGE; | ||
} | ||
this.range = value; | ||
} | ||
|
||
public void increaseRange() { | ||
if (range < MAXIMUM_RANGE) { | ||
range++; | ||
} | ||
} | ||
|
||
public void decreaseRange() { | ||
if (range > MINIMUM_RANGE) { | ||
range--; | ||
} | ||
} | ||
|
||
public boolean isInRange(double x, double y, double z) { | ||
return x >= this.xCoord - range && x <= this.xCoord + range + 1 | ||
&& y >= this.yCoord - range | ||
&& y <= this.yCoord + range + 1 | ||
&& z >= this.zCoord - range | ||
&& z <= this.zCoord + range + 1; | ||
} | ||
|
||
@Override | ||
public Packet getDescriptionPacket() { | ||
NBTTagCompound tagCompound = new NBTTagCompound(); | ||
this.writeToNBT(tagCompound); | ||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tagCompound); | ||
} | ||
|
||
@Override | ||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { | ||
readFromNBT(pkt.func_148857_g()); | ||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); | ||
} | ||
|
||
@Override | ||
public void writeToNBT(NBTTagCompound compound) { | ||
compound.setInteger("Range", range); | ||
super.writeToNBT(compound); | ||
} | ||
|
||
@Override | ||
public void readFromNBT(NBTTagCompound compound) { | ||
range = compound.getInteger("Range"); | ||
super.readFromNBT(compound); | ||
} | ||
} |
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
Binary file added
BIN
+877 Bytes
src/main/resources/assets/draconicevolution/textures/blocks/inhibitor_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.