use of crazypants.enderio.base.conduit.IServerConduit in project EnderIO by SleepyTrousers.
the class TileConduitBundle method onAfterNbtRead.
@Override
protected void onAfterNbtRead() {
super.onAfterNbtRead();
if (world.isRemote) {
// keep conduits sorted so the client side cache key is stable
ConduitRegistry.sort(conduits);
CopyOnWriteArrayList<IClientConduit> temp = new CopyOnWriteArrayList<>();
for (IConduit c : conduits) {
if (c instanceof IClientConduit) {
c.setBundle(this);
temp.add((IClientConduit) c);
}
}
final ConduitCacheKey oldHashCode = new ConduitCacheKey(), newHashCode = new ConduitCacheKey();
makeConduitHashCode(getClientConduits(), oldHashCode);
makeConduitHashCode(temp, newHashCode);
if (hasWorld() && getWorld().isRemote && oldHashCode.hashCode() != newHashCode.hashCode()) {
clientUpdated = true;
}
// switch over atomically to avoid threading issues
clientConduits = temp;
conduits = new CopyOnWriteArrayList<IConduit>();
} else {
// no threads on server-side. but to be safe, conduits only go into the list after they got a bundle set
// (a.k.a. "do better than World.addTileEntities()"
serverConduits.clear();
for (IConduit c : conduits) {
if (c instanceof IServerConduit) {
c.setBundle(this);
serverConduits.add((IServerConduit) c);
}
}
conduits.clear();
}
cachedCollidables.clear();
}
use of crazypants.enderio.base.conduit.IServerConduit in project EnderIO by SleepyTrousers.
the class AbstractItemConduit method onItemUse.
@Override
@Nonnull
public EnumActionResult onItemUse(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack held = player.getHeldItem(hand);
BlockPos placeAt = canPlaceItem(held, ConduitRegistry.getConduitModObjectNN().getBlockNN().getDefaultState(), player, world, pos, side);
if (placeAt != null) {
if (!world.isRemote) {
if (world.setBlockState(placeAt, ConduitRegistry.getConduitModObjectNN().getBlockNN().getDefaultState(), 1)) {
TileEntity te = world.getTileEntity(placeAt);
if (te instanceof IConduitBundle) {
IConduitBundle bundle = (IConduitBundle) te;
bundle.addConduit(createConduit(held, player));
ConduitUtil.playBreakSound(SoundType.METAL, world, placeAt);
}
}
}
if (!player.capabilities.isCreativeMode) {
held.shrink(1);
}
return EnumActionResult.SUCCESS;
} else {
BlockPos place = pos.offset(side);
if (world.getBlockState(place).getBlock() == ConduitRegistry.getConduitModObjectNN().getBlock()) {
IConduitBundle bundle = (IConduitBundle) world.getTileEntity(place);
if (bundle == null) {
return EnumActionResult.PASS;
}
if (!bundle.hasType(getBaseConduitType())) {
if (!world.isRemote) {
IServerConduit con = createConduit(held, player);
if (con == null) {
return EnumActionResult.PASS;
}
bundle.addConduit(con);
ConduitUtil.playBreakSound(SoundType.METAL, world, place);
if (!player.capabilities.isCreativeMode) {
held.shrink(1);
}
}
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.PASS;
}
use of crazypants.enderio.base.conduit.IServerConduit in project EnderIO by SleepyTrousers.
the class AbstractItemConduit method onItemUseFirst.
@Override
@Nonnull
public EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {
ItemStack held = player.getHeldItem(hand);
// Conduit replacement
if (player.isSneaking()) {
return EnumActionResult.PASS;
}
TileEntity te = world.getTileEntity(pos);
if (te == null || !(te instanceof IConduitBundle)) {
return EnumActionResult.PASS;
}
IConduitBundle bundle = (IConduitBundle) te;
IConduit existingConduit = bundle.getConduit(getBaseConduitType());
if (existingConduit == null) {
return EnumActionResult.PASS;
}
ItemStack existingConduitAsItemStack = existingConduit.createItem();
if (!ItemUtil.areStacksEqual(existingConduitAsItemStack, held)) {
if (!world.isRemote) {
IServerConduit newConduit = createConduit(held, player);
if (newConduit == null) {
return EnumActionResult.PASS;
}
bundle.removeConduit((IServerConduit) existingConduit);
bundle.addConduit(newConduit);
if (!player.capabilities.isCreativeMode) {
held.shrink(1);
for (ItemStack drop : existingConduit.getDrops()) {
if (!player.inventory.addItemStackToInventory(drop)) {
ItemUtil.spawnItemInWorldWithRandomMotion(world, drop, pos, hitX, hitY, hitZ, 1.1f);
}
}
player.inventoryContainer.detectAndSendChanges();
}
return EnumActionResult.FAIL;
} else {
player.swingArm(hand);
}
}
return EnumActionResult.PASS;
}
Aggregations