Moving to source sets
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
|
||||
public interface AEToolItem {
|
||||
ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
// TODO Villager Trading!??!?!
|
||||
|
||||
public class AETrading {
|
||||
|
||||
/*
|
||||
* @Override public void manipulateTradesForVillager( EntityVillager villager,
|
||||
* MerchantRecipeList recipeList, Random random ) { final IMaterials materials =
|
||||
* AEApi.instance().definitions().materials(); this.addMerchant( recipeList,
|
||||
* materials.silicon(), 1, random, 2 ); this.addMerchant( recipeList,
|
||||
* materials.certusQuartzCrystal(), 2, random, 4 ); this.addMerchant(
|
||||
* recipeList, materials.certusQuartzDust(), 1, random, 3 ); this.addTrade(
|
||||
* recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(),
|
||||
* random, 2 ); } private void addMerchant( MerchantRecipeList list,
|
||||
* IItemDefinition item, int emera, Random rand, int greed ) { for( ItemStack
|
||||
* itemStack : item.maybeStack( 1 ).asSet() ) { // Sell ItemStack from =
|
||||
* itemStack.copy(); ItemStack to = new ItemStack( Items.emerald ); int
|
||||
* multiplier = ( Math.abs( rand.nextInt() ) % 6 ); final int emeraldCost =
|
||||
* emera + ( Math.abs( rand.nextInt() ) % greed ) - multiplier; int mood =
|
||||
* rand.nextInt() % 2; from.stackSize = multiplier + mood; to.stackSize =
|
||||
* multiplier * emeraldCost - mood; if( to.stackSize < 0 ) { from.stackSize -=
|
||||
* to.stackSize; to.stackSize -= to.stackSize; } this.addToList( list, from, to
|
||||
* ); // Buy ItemStack reverseTo = from.copy(); ItemStack reverseFrom =
|
||||
* to.copy(); reverseFrom.stackSize *= rand.nextFloat() * 3.0f + 1.0f;
|
||||
* this.addToList( list, reverseFrom, reverseTo ); } } private void addTrade(
|
||||
* MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition
|
||||
* outputDefinition, Random rand, int conversionVariance ) { final
|
||||
* Optional<ItemStack> maybeInputStack = inputDefinition.maybeStack( 1 ); final
|
||||
* Optional<ItemStack> maybeOutputStack = outputDefinition.maybeStack( 1 ); if(
|
||||
* maybeInputStack.isPresent() && maybeOutputStack.isPresent() ) { // Sell
|
||||
* ItemStack inputStack = maybeInputStack.get().copy(); ItemStack outputStack =
|
||||
* maybeOutputStack.get().copy(); inputStack.stackSize = 1 + ( Math.abs(
|
||||
* rand.nextInt() ) % ( 1 + conversionVariance ) ); outputStack.stackSize = 1;
|
||||
* this.addToList( list, inputStack, outputStack ); } } private void addToList(
|
||||
* MerchantRecipeList l, ItemStack a, ItemStack b ) { if( a.stackSize < 1 ) {
|
||||
* a.stackSize = 1; } if( b.stackSize < 1 ) { b.stackSize = 1; } if( a.stackSize
|
||||
* > a.getMaxStackSize() ) { a.stackSize = a.getMaxStackSize(); } if(
|
||||
* b.stackSize > b.getMaxStackSize() ) { b.stackSize = b.getMaxStackSize(); }
|
||||
* l.add( new MerchantRecipe( a, b ) ); }
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.parts.CableRenderMode;
|
||||
import appeng.client.AppEngClient;
|
||||
import appeng.util.Platform;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ClientTickHandler extends TickHandler {
|
||||
|
||||
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<>();
|
||||
private CableRenderMode crm = CableRenderMode.STANDARD;
|
||||
|
||||
public ClientTickHandler() {
|
||||
ClientTickEvents.START_CLIENT_TICK.register(this::onBeforeClientTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, PlayerColor> getPlayerColors() {
|
||||
if (!Platform.isServer()) {
|
||||
return this.cliPlayerColors;
|
||||
}
|
||||
return super.getPlayerColors();
|
||||
}
|
||||
|
||||
private void onBeforeClientTick(MinecraftClient client) {
|
||||
this.tickColors(this.cliPlayerColors);
|
||||
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
|
||||
if (currentMode != this.crm) {
|
||||
this.crm = currentMode;
|
||||
AppEngClient.instance().triggerUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.CompassRequestPacket;
|
||||
|
||||
public class CompassManager {
|
||||
|
||||
public static final CompassManager INSTANCE = new CompassManager();
|
||||
private final HashMap<CompassRequest, CompassResult> requests = new HashMap<>();
|
||||
|
||||
public void postResult(final long attunement, final int x, final int y, final int z, final CompassResult result) {
|
||||
final CompassRequest r = new CompassRequest(attunement, x, y, z);
|
||||
this.requests.put(r, result);
|
||||
}
|
||||
|
||||
public CompassResult getCompassDirection(final long attunement, final int x, final int y, final int z) {
|
||||
final long now = System.currentTimeMillis();
|
||||
|
||||
final Iterator<CompassResult> i = this.requests.values().iterator();
|
||||
while (i.hasNext()) {
|
||||
final CompassResult res = i.next();
|
||||
final long diff = now - res.getTime();
|
||||
if (diff > 20000) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
final CompassRequest r = new CompassRequest(attunement, x, y, z);
|
||||
CompassResult res = this.requests.get(r);
|
||||
|
||||
if (res == null) {
|
||||
res = new CompassResult(false, true, 0);
|
||||
this.requests.put(r, res);
|
||||
this.requestUpdate(r);
|
||||
} else if (now - res.getTime() > 1000 * 3) {
|
||||
if (!res.isRequested()) {
|
||||
res.setRequested(true);
|
||||
this.requestUpdate(r);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private void requestUpdate(final CompassRequest r) {
|
||||
NetworkHandler.instance().sendToServer(new CompassRequestPacket(r.attunement, r.cx, r.cz, r.cdy));
|
||||
}
|
||||
|
||||
private static class CompassRequest {
|
||||
|
||||
private final int hash;
|
||||
private final long attunement;
|
||||
private final int cx;
|
||||
private final int cdy;
|
||||
private final int cz;
|
||||
|
||||
public CompassRequest(final long attunement, final int x, final int y, final int z) {
|
||||
this.attunement = attunement;
|
||||
this.cx = x >> 4;
|
||||
this.cdy = y >> 5;
|
||||
this.cz = z >> 4;
|
||||
this.hash = ((Integer) this.cx).hashCode() ^ ((Integer) this.cdy).hashCode()
|
||||
^ ((Integer) this.cz).hashCode() ^ ((Long) attunement).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CompassRequest other = (CompassRequest) obj;
|
||||
return this.attunement == other.attunement && this.cx == other.cx && this.cdy == other.cdy
|
||||
&& this.cz == other.cz;
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
-5
@@ -18,11 +18,42 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
public class CompassResult {
|
||||
|
||||
public interface IBlockTool {
|
||||
// Workaround for dispenser logic.
|
||||
ActionResult onItemUse(ItemUsageContext itemUseContext);
|
||||
private final boolean hasResult;
|
||||
private final boolean spin;
|
||||
private final double rad;
|
||||
private final long time;
|
||||
private boolean requested = false;
|
||||
|
||||
public CompassResult(final boolean hasResult, final boolean spin, final double rad) {
|
||||
this.hasResult = hasResult;
|
||||
this.spin = spin;
|
||||
this.rad = rad;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean isValidResult() {
|
||||
return this.hasResult;
|
||||
}
|
||||
|
||||
public boolean isSpin() {
|
||||
return this.spin;
|
||||
}
|
||||
|
||||
public double getRad() {
|
||||
return this.rad;
|
||||
}
|
||||
|
||||
boolean isRequested() {
|
||||
return this.requested;
|
||||
}
|
||||
|
||||
void setRequested(final boolean requested) {
|
||||
this.requested = requested;
|
||||
}
|
||||
|
||||
long getTime() {
|
||||
return this.time;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
import appeng.util.FakePlayer;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.dispenser.ItemDispenserBehavior;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.items.tools.powered.MatterCannonItem;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final class MatterCannonDispenseItemBehavior extends ItemDispenserBehavior {
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseSilently(final BlockPointer dispenser, ItemStack dispensedItem) {
|
||||
final Item i = dispensedItem.getItem();
|
||||
if (i instanceof MatterCannonItem) {
|
||||
final Direction Direction = dispenser.getBlockState().get(DispenserBlock.FACING);
|
||||
AEPartLocation dir = AEPartLocation.INTERNAL;
|
||||
for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) {
|
||||
if (Direction.getOffsetX() == d.xOffset && Direction.getOffsetY() == d.yOffset
|
||||
&& Direction.getOffsetZ() == d.zOffset) {
|
||||
dir = d;
|
||||
}
|
||||
}
|
||||
|
||||
final MatterCannonItem tm = (MatterCannonItem) i;
|
||||
|
||||
final World w = dispenser.getWorld();
|
||||
if (w instanceof ServerWorld) {
|
||||
final PlayerEntity p = FakePlayer.getOrCreate((ServerWorld) w);
|
||||
Platform.configurePlayer(p, dir, dispenser.getBlockTileEntity());
|
||||
|
||||
p.updatePosition(p.getX() + dir.xOffset, p.getY() + dir.yOffset, p.getZ() + dir.zOffset);
|
||||
|
||||
dispensedItem = tm.use(w, p, null).getResult();
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.packets.PaintedEntityPacket;
|
||||
import appeng.crafting.CraftingJob;
|
||||
import appeng.me.Grid;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TickHandler {
|
||||
|
||||
public static final TickHandler INSTANCE = new TickHandler();
|
||||
private final Queue<IWorldCallable<?>> serverQueue = new ArrayDeque<>();
|
||||
private final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
|
||||
private final WeakHashMap<WorldAccess, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
|
||||
private final HandlerRep server = new HandlerRep();
|
||||
private final HandlerRep client = new HandlerRep();
|
||||
private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>();
|
||||
|
||||
public TickHandler() {
|
||||
// Register for all the tick events we care about
|
||||
ServerTickEvents.END_SERVER_TICK.register(this::onAfterServerTick);
|
||||
ServerTickEvents.START_WORLD_TICK.register(this::onBeforeWorldTick);
|
||||
ServerTickEvents.END_WORLD_TICK.register(this::onAfterWorldTick);
|
||||
|
||||
}
|
||||
|
||||
public HashMap<Integer, PlayerColor> getPlayerColors() {
|
||||
return this.srvPlayerColors;
|
||||
}
|
||||
|
||||
public void addCallable(final WorldAccess w, final IWorldCallable<?> c) {
|
||||
if (w == null) {
|
||||
this.serverQueue.add(c);
|
||||
} else {
|
||||
Queue<IWorldCallable<?>> queue = this.callQueue.get(w);
|
||||
|
||||
if (queue == null) {
|
||||
queue = new ArrayDeque<>();
|
||||
this.callQueue.put(w, queue);
|
||||
}
|
||||
|
||||
queue.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
public void addInit(final AEBaseBlockEntity tile) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().tiles.add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
private HandlerRep getRepo() {
|
||||
if (Platform.isServer()) {
|
||||
return this.server;
|
||||
}
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public void addNetwork(final Grid grid) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().addNetwork(grid);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNetwork(final Grid grid) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().removeNetwork(grid);
|
||||
}
|
||||
}
|
||||
|
||||
public Iterable<Grid> getGridList() {
|
||||
return this.getRepo().networks;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.getRepo().clear();
|
||||
}
|
||||
|
||||
// FIXME FABRIC It does not look like worlds can ever unload in Fabric.
|
||||
// FIXME FABRIC public void unloadWorld(final WorldEvent.Unload ev) {
|
||||
// FIXME FABRIC if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
// FIXME FABRIC {
|
||||
// FIXME FABRIC final List<IGridNode> toDestroy = new ArrayList<>();
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC this.getRepo().updateNetworks();
|
||||
// FIXME FABRIC for (final Grid g : this.getRepo().networks) {
|
||||
// FIXME FABRIC for (final IGridNode n : g.getNodes()) {
|
||||
// FIXME FABRIC if (n.getWorld() == ev.getWorld()) {
|
||||
// FIXME FABRIC toDestroy.add(n);
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC for (final IGridNode n : toDestroy) {
|
||||
// FIXME FABRIC n.destroy();
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
|
||||
private void onBeforeWorldTick(ServerWorld world) {
|
||||
final Queue<IWorldCallable<?>> queue = this.callQueue.get(world);
|
||||
this.processQueue(queue, world);
|
||||
}
|
||||
|
||||
private void onAfterWorldTick(ServerWorld world) {
|
||||
synchronized (this.craftingJobs) {
|
||||
final Collection<CraftingJob> jobSet = this.craftingJobs.get(world);
|
||||
if (!jobSet.isEmpty()) {
|
||||
final int simTime = Math.max(1,
|
||||
AEConfig.instance().getCraftingCalculationTimePerTick() / jobSet.size());
|
||||
final Iterator<CraftingJob> i = jobSet.iterator();
|
||||
while (i.hasNext()) {
|
||||
final CraftingJob cj = i.next();
|
||||
if (!cj.simulateFor(simTime)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onAfterServerTick(MinecraftServer server) {
|
||||
this.tickColors(this.srvPlayerColors);
|
||||
// ready tiles.
|
||||
final HandlerRep repo = this.getRepo();
|
||||
while (!repo.tiles.isEmpty()) {
|
||||
final AEBaseBlockEntity bt = repo.tiles.poll();
|
||||
if (!bt.isRemoved()) {
|
||||
bt.onReady();
|
||||
}
|
||||
}
|
||||
|
||||
// tick networks.
|
||||
this.getRepo().updateNetworks();
|
||||
for (final Grid g : this.getRepo().networks) {
|
||||
g.update();
|
||||
}
|
||||
|
||||
// cross world queue.
|
||||
this.processQueue(this.serverQueue, null);
|
||||
}
|
||||
|
||||
protected void tickColors(final HashMap<Integer, PlayerColor> playerSet) {
|
||||
final Iterator<PlayerColor> i = playerSet.values().iterator();
|
||||
while (i.hasNext()) {
|
||||
final PlayerColor pc = i.next();
|
||||
if (pc.ticksLeft <= 0) {
|
||||
i.remove();
|
||||
}
|
||||
pc.ticksLeft--;
|
||||
}
|
||||
}
|
||||
|
||||
private void processQueue(final Queue<IWorldCallable<?>> queue, final World world) {
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Stopwatch sw = Stopwatch.createStarted();
|
||||
|
||||
IWorldCallable<?> c = null;
|
||||
while ((c = queue.poll()) != null) {
|
||||
try {
|
||||
c.call(world);
|
||||
|
||||
if (sw.elapsed(TimeUnit.MILLISECONDS) > 50) {
|
||||
break;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
// long time = sw.elapsed( TimeUnit.MILLISECONDS );
|
||||
// if ( time > 0 )
|
||||
// AELog.info( "processQueue Time: " + time + "ms" );
|
||||
}
|
||||
|
||||
public void registerCraftingSimulation(final World world, final CraftingJob craftingJob) {
|
||||
synchronized (this.craftingJobs) {
|
||||
this.craftingJobs.put(world, craftingJob);
|
||||
}
|
||||
}
|
||||
|
||||
private static class HandlerRep {
|
||||
|
||||
private Queue<AEBaseBlockEntity> tiles = new ArrayDeque<>();
|
||||
private Set<Grid> networks = new HashSet<>();
|
||||
private Set<Grid> toAdd = new HashSet<>();
|
||||
private Set<Grid> toRemove = new HashSet<>();
|
||||
|
||||
private void clear() {
|
||||
this.tiles = new ArrayDeque<>();
|
||||
this.networks = new HashSet<>();
|
||||
this.toAdd = new HashSet<>();
|
||||
this.toRemove = new HashSet<>();
|
||||
}
|
||||
|
||||
private synchronized void addNetwork(Grid g) {
|
||||
this.toAdd.add(g);
|
||||
this.toRemove.remove(g);
|
||||
}
|
||||
|
||||
private synchronized void removeNetwork(Grid g) {
|
||||
this.toRemove.add(g);
|
||||
this.toAdd.remove(g);
|
||||
}
|
||||
|
||||
private synchronized void updateNetworks() {
|
||||
this.networks.removeAll(this.toRemove);
|
||||
this.toRemove.clear();
|
||||
|
||||
this.networks.addAll(this.toAdd);
|
||||
this.toAdd.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerColor {
|
||||
|
||||
public final AEColor myColor;
|
||||
private final int myEntity;
|
||||
private int ticksLeft;
|
||||
|
||||
public PlayerColor(final int id, final AEColor col, final int ticks) {
|
||||
this.myEntity = id;
|
||||
this.myColor = col;
|
||||
this.ticksLeft = ticks;
|
||||
}
|
||||
|
||||
public PaintedEntityPacket getPacket() {
|
||||
return new PaintedEntityPacket(this.myEntity, this.myColor, this.ticksLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-17
@@ -21,30 +21,25 @@ package appeng.hooks;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.dispenser.ItemDispenserBehavior;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.item.AutomaticItemPlacementContext;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
public final class BlockToolDispenseItemBehavior extends ItemDispenserBehavior {
|
||||
import appeng.entity.TinyTNTPrimedEntity;
|
||||
|
||||
public final class TinyTNTDispenseItemBehavior extends ItemDispenserBehavior {
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseSilently(final BlockPointer dispenser, final ItemStack dispensedItem) {
|
||||
final Item i = dispensedItem.getItem();
|
||||
if (i instanceof IBlockTool) {
|
||||
final Direction direction = dispenser.getBlockState().get(DispenserBlock.FACING);
|
||||
final IBlockTool tm = (IBlockTool) i;
|
||||
|
||||
final World w = dispenser.getWorld();
|
||||
if (w instanceof ServerWorld) {
|
||||
ItemUsageContext context = new AutomaticItemPlacementContext(w, dispenser.getBlockPos().offset(direction),
|
||||
direction, dispensedItem, direction.getOpposite());
|
||||
tm.onItemUse(context);
|
||||
}
|
||||
}
|
||||
final Direction Direction = dispenser.getBlockState().get(DispenserBlock.FACING);
|
||||
final World world = dispenser.getWorld();
|
||||
final int i = dispenser.getBlockPos().getX() + Direction.getOffsetX();
|
||||
final int j = dispenser.getBlockPos().getY() + Direction.getOffsetY();
|
||||
final int k = dispenser.getBlockPos().getZ() + Direction.getOffsetZ();
|
||||
final TinyTNTPrimedEntity primedTinyTNTEntity = new TinyTNTPrimedEntity(world, i + 0.5F, j + 0.5F, k + 0.5F,
|
||||
null);
|
||||
world.spawnEntity(primedTinyTNTEntity);
|
||||
dispensedItem.setCount(dispensedItem.getCount() - 1);
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* This hooks allows item-specific behavior to be triggered when an item is used on a block,
|
||||
* without shift being held or the block being called first.
|
||||
*/
|
||||
public class ToolItemHook {
|
||||
|
||||
public static void install() {
|
||||
UseBlockCallback.EVENT.register(ToolItemHook::handleItemUse);
|
||||
}
|
||||
|
||||
private static ActionResult handleItemUse(PlayerEntity playerEntity, World world, Hand hand, BlockHitResult blockHitResult) {
|
||||
|
||||
if (playerEntity.isSpectator()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
ItemStack itemStack = playerEntity.getStackInHand(hand);
|
||||
Item item = itemStack.getItem();
|
||||
if (item instanceof AEToolItem) {
|
||||
ItemUsageContext context = new ItemUsageContext(playerEntity, hand, blockHitResult);
|
||||
AEToolItem toolItem = (AEToolItem) item;
|
||||
return toolItem.onItemUseFirst(itemStack, context);
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user