mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Added laser range upgrade
This commit is contained in:
parent
6d3ef21444
commit
e8d89f6df4
9 changed files with 85 additions and 11 deletions
|
@ -35,6 +35,8 @@ public interface ILaserRelayConnectionHandler{
|
|||
|
||||
boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world, boolean suppressConnectionRender);
|
||||
|
||||
void removeConnection(World world, BlockPos firstRelay, BlockPos secondRelay);
|
||||
|
||||
LaserType getTypeFromLaser(TileEntity tile);
|
||||
|
||||
LaserType getTypeFromLaser(BlockPos pos, World world);
|
||||
|
|
|
@ -161,6 +161,7 @@ public class CreativeTab extends CreativeTabs{
|
|||
this.add(InitItems.itemMiningLens);
|
||||
this.add(InitItems.itemLaserWrench);
|
||||
this.add(InitItems.itemLaserUpgradeInvisibility);
|
||||
this.add(InitItems.itemLaserUpgradeRange);
|
||||
this.add(InitItems.itemInfraredGoggles);
|
||||
this.add(InitItems.itemCrateKeeper);
|
||||
this.add(InitItems.itemChestToCrateUpgrade);
|
||||
|
|
|
@ -194,12 +194,14 @@ public final class InitItems{
|
|||
public static Item itemVoidBag;
|
||||
public static Item itemFillingWand;
|
||||
public static Item itemLaserUpgradeInvisibility;
|
||||
public static Item itemLaserUpgradeRange;
|
||||
public static Item itemInfraredGoggles;
|
||||
|
||||
public static void init(){
|
||||
ModUtil.LOGGER.info("Initializing Items...");
|
||||
|
||||
itemInfraredGoggles = new ItemInfraredGoggles("item_infrared_goggles");
|
||||
itemLaserUpgradeRange = new ItemLaserRelayUpgrade("item_laser_upgrade_range");
|
||||
itemLaserUpgradeInvisibility = new ItemLaserRelayUpgrade("item_laser_upgrade_invisibility");
|
||||
itemFillingWand = new ItemFillingWand("item_filling_wand");
|
||||
itemBag = new ItemBag("item_bag", false);
|
||||
|
|
|
@ -43,6 +43,7 @@ public class ItemLaserWrench extends ItemBase{
|
|||
ItemStack stack = player.getHeldItem(hand);
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityLaserRelay){
|
||||
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
|
||||
if(!world.isRemote){
|
||||
if(ItemPhantomConnector.getStoredPosition(stack) == null){
|
||||
ItemPhantomConnector.storeConnection(stack, pos.getX(), pos.getY(), pos.getZ(), world);
|
||||
|
@ -52,20 +53,26 @@ public class ItemLaserWrench extends ItemBase{
|
|||
BlockPos savedPos = ItemPhantomConnector.getStoredPosition(stack);
|
||||
if(savedPos != null){
|
||||
TileEntity savedTile = world.getTileEntity(savedPos);
|
||||
int distanceSq = (int)savedPos.distanceSq(pos);
|
||||
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
|
||||
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).type == relay.type && distanceSq <= TileEntityLaserRelay.MAX_DISTANCE*TileEntityLaserRelay.MAX_DISTANCE && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, relay.type, world)){
|
||||
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
|
||||
if(savedTile instanceof TileEntityLaserRelay){
|
||||
int distanceSq = (int)savedPos.distanceSq(pos);
|
||||
TileEntityLaserRelay savedRelay = (TileEntityLaserRelay)savedTile;
|
||||
|
||||
((TileEntityLaserRelay)savedTile).sendUpdate();
|
||||
relay.sendUpdate();
|
||||
int lowestRange = Math.min(relay.getMaxRange(), savedRelay.getMaxRange());
|
||||
int range = lowestRange*lowestRange;
|
||||
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedRelay.type == relay.type && distanceSq <= range && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, relay.type, world)){
|
||||
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
|
||||
|
||||
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
|
||||
}
|
||||
else{
|
||||
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.cantConnect.desc"));
|
||||
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
|
||||
((TileEntityLaserRelay)savedTile).sendUpdate();
|
||||
relay.sendUpdate();
|
||||
|
||||
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.cantConnect.desc"));
|
||||
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,6 +170,27 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeConnection(World world, BlockPos firstRelay, BlockPos secondRelay){
|
||||
if(world != null && firstRelay != null && secondRelay != null){
|
||||
Network network = this.getNetworkFor(firstRelay, world);
|
||||
|
||||
if(network != null){
|
||||
network.changeAmount++;
|
||||
|
||||
WorldData data = WorldData.get(world);
|
||||
data.laserRelayNetworks.remove(network);
|
||||
data.markDirty();
|
||||
|
||||
for(IConnectionPair pair : network.connections){
|
||||
if(!pair.contains(firstRelay) || !pair.contains(secondRelay)){
|
||||
this.addConnection(pair.getPositions()[0], pair.getPositions()[1], pair.getType(), world, pair.doesSuppressRender());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LaserType getTypeFromLaser(TileEntity tile){
|
||||
if(tile instanceof TileEntityLaserRelay){
|
||||
|
|
|
@ -14,9 +14,12 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|||
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
||||
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
||||
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.ConnectionPair;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -35,6 +38,7 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase{
|
|||
|
||||
private Network cachedNetwork;
|
||||
private int changeAmountAtCaching = -1;
|
||||
private int lastRange;
|
||||
|
||||
private Set<IConnectionPair> tempConnectionStorage;
|
||||
|
||||
|
@ -81,6 +85,26 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
|
||||
int range = this.getMaxRange();
|
||||
if(this.lastRange != range){
|
||||
ConcurrentSet<IConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.world);
|
||||
if(connections != null && !connections.isEmpty()){
|
||||
for(IConnectionPair pair : connections){
|
||||
int distanceSq = (int)pair.getPositions()[0].distanceSq(pair.getPositions()[1]);
|
||||
if(distanceSq > range*range){
|
||||
ActuallyAdditionsAPI.connectionHandler.removeConnection(this.world, pair.getPositions()[0], pair.getPositions()[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.lastRange = range;
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
|
@ -166,6 +190,16 @@ public abstract class TileEntityLaserRelay extends TileEntityInventoryBase{
|
|||
return null;
|
||||
}
|
||||
|
||||
public int getMaxRange(){
|
||||
ItemStack upgrade = this.slots.getStackInSlot(0);
|
||||
if(StackUtil.isValid(upgrade) && upgrade.getItem() == InitItems.itemLaserUpgradeRange){
|
||||
return 35;
|
||||
}
|
||||
else{
|
||||
return MAX_DISTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract String getExtraDisplayString();
|
||||
|
||||
|
|
|
@ -522,6 +522,7 @@ item.actuallyadditions.item_more_damage_lens.name=Lens of the Killer
|
|||
item.actuallyadditions.item_filling_wand.name=Handheld Filler
|
||||
item.actuallyadditions.item_laser_upgrade_invisibility.name=Laser Relay Modifier: Invisibility
|
||||
item.actuallyadditions.item_infrared_goggles.name=Infrared Goggles
|
||||
item.actuallyadditions.item_laser_upgrade_range.name=Laser Relay Modifier: Range
|
||||
|
||||
#Tooltips
|
||||
tooltip.actuallyadditions.onSuffix.desc=On
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "actuallyadditions:item/handheld_item",
|
||||
"textures": {
|
||||
"layer0": "actuallyadditions:items/item_laser_upgrade_range"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 265 B |
Loading…
Reference in a new issue