use of net.minecraft.block.entity.BlockEntity in project roadrunner by MaxNeedsSnacks.
the class BlockEntityList method remove.
@Override
public boolean remove(Object o) {
if (o instanceof BlockEntity) {
BlockEntity blockEntity = (BlockEntity) o;
if (currentlyOffThread()) {
addOffThreadOperation(new OffThreadOperation(blockEntity, OperationType.REMOVE));
return true;
}
checkOffThreadModifications(false);
if (this.allBlockEntities.remove(o)) {
if (this.posMap != null) {
long pos = getEntityPos(blockEntity);
List<BlockEntity> multiEntry = this.posMapMulti.get(pos);
if (multiEntry != null) {
multiEntry.remove(blockEntity);
if (multiEntry.size() <= 1) {
this.posMapMulti.remove(pos);
}
}
if (multiEntry != null && multiEntry.size() > 0) {
this.posMap.put(pos, multiEntry.get(0));
} else {
this.posMap.remove(pos);
}
}
return true;
}
}
return false;
}
use of net.minecraft.block.entity.BlockEntity in project roadrunner by MaxNeedsSnacks.
the class BlockEntityList method addNoDoubleAdd.
private boolean addNoDoubleAdd(BlockEntity blockEntity, boolean exceptionOnDoubleAdd) {
if (currentlyOffThread()) {
// Off-thread adds are always treated as "if absent", otherwise the most typical case (race on
// getBlockEntity) would always crash
addOffThreadOperation(new OffThreadOperation(blockEntity, OperationType.ADD));
return true;
}
checkOffThreadModifications(false);
boolean added = this.allBlockEntities.add(blockEntity);
if (!added && exceptionOnDoubleAdd && // Ignore double add when we encounter vanilla's command block double add bug
!(blockEntity instanceof CommandBlockBlockEntity)) {
this.throwException(blockEntity);
}
if (added && this.posMap != null) {
long pos = getEntityPos(blockEntity);
BlockEntity prev = this.posMap.putIfAbsent(pos, blockEntity);
if (prev != null) {
List<BlockEntity> multiEntry = this.posMapMulti.computeIfAbsent(pos, (long l) -> new ArrayList<>());
if (multiEntry.size() == 0) {
// newly created multi entry: make sure it contains all elements
multiEntry.add(prev);
}
multiEntry.add(blockEntity);
}
}
return added;
}
use of net.minecraft.block.entity.BlockEntity in project Polymorph by TheIllusiveC4.
the class CommonEventsListener method worldTick.
private static void worldTick(final ServerWorld serverWorld) {
List<BlockEntity> toRemove = new ArrayList<>();
for (Map.Entry<BlockEntity, BlockEntityRecipeData> entry : TICKABLE_BLOCKS.entrySet()) {
BlockEntity be = entry.getKey();
World beWorld = be.getWorld();
if (be.isRemoved() || beWorld == null || beWorld.isClient()) {
toRemove.add(be);
} else {
entry.getValue().tick();
}
}
for (BlockEntity be : toRemove) {
TICKABLE_BLOCKS.remove(be);
}
}
use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.
the class AutoSteal method onTick.
@BleachSubscribe
public void onTick(EventTick event) {
currentTime++;
for (Entry<BlockPos, Integer> e : new HashMap<>(opened).entrySet()) {
if (e.getValue() <= 0)
opened.remove(e.getKey());
else
opened.replace(e.getKey(), e.getValue() - 1);
}
if (currentItems != null && currentSyncId != -1) {
if (currentTime - lastSteal >= getSetting(1).asSlider().getValue()) {
for (int i = 0; i < currentItems.size(); i++) {
if (!currentItems.get(i).isEmpty()) {
if (isBlacklisted(currentItems.get(i).getItem())) {
continue;
}
int fi = i;
boolean openSlot = InventoryUtils.getSlot(false, j -> mc.player.getInventory().getStack(j).isEmpty() || (mc.player.getInventory().getStack(j).isStackable() && mc.player.getInventory().getStack(j).getCount() < mc.player.getInventory().getStack(j).getMaxCount() && currentItems.get(fi).isItemEqual(mc.player.getInventory().getStack(j)))) != 1;
if (openSlot) {
mc.interactionManager.clickSlot(currentSyncId, i, 0, SlotActionType.QUICK_MOVE, mc.player);
currentItems.set(i, ItemStack.EMPTY);
lastSteal = currentTime + RandomUtils.nextInt(0, getSetting(2).asSlider().getValueInt() + 1);
}
return;
}
}
if (getSetting(0).asMode().getMode() >= 1 || getSetting(3).asToggle().getState()) {
mc.setScreen(null);
mc.player.networkHandler.sendPacket(new CloseHandledScreenC2SPacket(currentSyncId));
}
}
} else if (currentItems == null && currentSyncId == -1 && getSetting(3).asToggle().getState()) {
for (BlockEntity be : WorldUtils.getBlockEntities()) {
if (!opened.containsKey(be.getPos()) && be instanceof ChestBlockEntity && mc.player.getEyePos().distanceTo(Vec3d.ofCenter(be.getPos())) <= getSetting(3).asToggle().getChild(0).asSlider().getValue() + 0.25) {
Vec3d lookVec = Vec3d.ofCenter(be.getPos()).add(0, 0.5, 0);
if (getSetting(3).asToggle().getChild(2).asRotate().getState()) {
WorldUtils.facePosAuto(lookVec.x, lookVec.y, lookVec.z, getSetting(3).asToggle().getChild(2).asRotate());
}
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(lookVec, Direction.UP, be.getPos(), false));
opened.put(be.getPos(), getSetting(3).asToggle().getChild(1).asSlider().getValueInt() * 20);
return;
}
}
}
}
use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.
the class BlockHighlight method onWorldRender.
@BleachSubscribe
public void onWorldRender(EventWorldRender.Post event) {
int mode = getSetting(0).asMode().getMode();
if (!(mc.crosshairTarget instanceof BlockHitResult))
return;
BlockPos pos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
BlockState state = mc.world.getBlockState(pos);
if (state.getMaterial() == Material.AIR || !mc.world.getWorldBorder().contains(pos))
return;
int[] color = this.getSetting(4).asColor().getRGBArray();
if (mode == 0) {
shader.prepare();
shader.clearFramebuffer("main");
Vec3d offset = state.getModelOffset(mc.world, pos);
MatrixStack matrices = Renderer.matrixFrom(pos.getX() + offset.x, pos.getY() + offset.y, pos.getZ() + offset.z);
BlockEntity be = mc.world.getBlockEntity(pos);
BlockEntityRenderer<BlockEntity> renderer = be != null ? mc.getBlockEntityRenderDispatcher().get(be) : null;
if (renderer != null) {
renderer.render(be, mc.getTickDelta(), matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()), LightmapTextureManager.MAX_LIGHT_COORDINATE, OverlayTexture.DEFAULT_UV);
} else {
mc.getBlockRenderManager().getModelRenderer().renderFlat(mc.world, mc.getBlockRenderManager().getModel(state), state, pos, matrices, colorVertexer.createSingleProvider(mc.getBufferBuilders().getEntityVertexConsumers(), color[0], color[1], color[2], getSetting(1).asSlider().getValueInt()).getBuffer(RenderLayers.getMovingBlockLayer(state)), false, new Random(), 0L, OverlayTexture.DEFAULT_UV);
}
colorVertexer.draw();
shader.render();
shader.drawFramebufferToMain("main");
} else {
Box box = state.getOutlineShape(mc.world, pos).getBoundingBox().offset(pos);
float width = getSetting(2).asSlider().getValueFloat();
int fill = getSetting(3).asSlider().getValueInt();
if (width != 0)
Renderer.drawBoxOutline(box, QuadColor.single(color[0], color[1], color[2], 255), width);
if (fill != 0)
Renderer.drawBoxFill(box, QuadColor.single(color[0], color[1], color[2], fill));
}
}
Aggregations