Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple way to replace bulbs and wires in lamp sockets #493

Merged
merged 1 commit into from
Jul 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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