Skip to content

Commit

Permalink
Merge pull request #493 from Electrical-Age/feature/simple-bulb-change
Browse files Browse the repository at this point in the history
Simple way to replace bulbs and wires in lamp sockets
  • Loading branch information
cm0x4D authored Jul 14, 2016
2 parents 01dcbbe + e9db444 commit 242eb2a
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/main/java/mods/eln/sixnode/lampsocket/LampSocketElement.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mods.eln.sixnode.lampsocket;

import mods.eln.Eln;
import mods.eln.generic.GenericItemBlockUsingDamageDescriptor;
import mods.eln.generic.GenericItemUsingDamageDescriptor;
import mods.eln.item.BrushDescriptor;
import mods.eln.item.LampDescriptor;
Expand All @@ -22,7 +23,6 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

Expand Down Expand Up @@ -266,17 +266,32 @@ public boolean onBlockActivated(EntityPlayer entityPlayer, Direction side, float

ItemStack currentItemStack = entityPlayer.getCurrentEquippedItem();
if (currentItemStack != null) {
Item item = currentItemStack.getItem();

GenericItemUsingDamageDescriptor gen = BrushDescriptor.getDescriptor(currentItemStack);
if (gen != null && gen instanceof BrushDescriptor) {
BrushDescriptor brush = (BrushDescriptor) gen;
int brushColor = brush.getColor(currentItemStack);
if (brushColor != paintColor && brush.use(currentItemStack,entityPlayer)) {
paintColor = brushColor;
needPublish(); //Sync
GenericItemUsingDamageDescriptor itemDescriptor = GenericItemUsingDamageDescriptor.getDescriptor(currentItemStack);
if (itemDescriptor != null) {
if (itemDescriptor instanceof BrushDescriptor) {
BrushDescriptor brush = (BrushDescriptor) itemDescriptor;
int brushColor = brush.getColor(currentItemStack);
if (brushColor != paintColor && brush.use(currentItemStack,entityPlayer)) {
paintColor = brushColor;
needPublish(); //Sync
}
return true;
} else if (itemDescriptor instanceof LampDescriptor && inventory.getStackInSlot(0) == null) {
currentItemStack.stackSize -= 1;
inventory.setInventorySlotContents(0, itemDescriptor.newItemStack());
needPublish();
return true;
}
} else {
GenericItemBlockUsingDamageDescriptor blockDescriptor = GenericItemBlockUsingDamageDescriptor.getDescriptor(currentItemStack);
if (blockDescriptor != null) {
if (blockDescriptor instanceof ElectricalCableDescriptor && inventory.getStackInSlot(1) == null) {
currentItemStack.stackSize -= 1;
inventory.setInventorySlotContents(1, blockDescriptor.newItemStack());
reconnect();
return true;
}
}
return true;
}
}

Expand Down

0 comments on commit 242eb2a

Please sign in to comment.