Skip to content

Commit

Permalink
transfer progress
Browse files Browse the repository at this point in the history
  • Loading branch information
GL33P-0R4NG3 committed Jul 26, 2021
1 parent 96d8ca3 commit 4982e94
Show file tree
Hide file tree
Showing 20 changed files with 889 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/main/java/me/gleep/oreganized/Oreganized.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import me.gleep.oreganized.entities.ShrapnelTNTEntity;
import me.gleep.oreganized.entities.entityrenderer.LeadNuggetRenderer;
import me.gleep.oreganized.entities.entityrenderer.ShrapnelTNTRenderer;
import me.gleep.oreganized.entities.entityrenderer.StoneSignRenderer;
import me.gleep.oreganized.particles.DawnShineParticle;
import me.gleep.oreganized.tools.STSBase;
import me.gleep.oreganized.util.RegistryHandler;
import me.gleep.oreganized.util.SimpleNetwork;
import me.gleep.oreganized.world.gen.CustomOreGen;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
Expand All @@ -29,6 +31,7 @@
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
Expand Down Expand Up @@ -57,10 +60,13 @@ private void setup(final FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
CustomOreGen.registerOres();
});
event.enqueueWork(() -> {
SimpleNetwork.register();
});
}

private void doClientStuff(final FMLClientSetupEvent event) {
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
ClientRegistry.bindTileEntityRenderer(RegistryHandler.STONE_SIGN_TE.get(), StoneSignRenderer::new);

RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.SHRAPNEL_TNT_ENTITY.get(), ShrapnelTNTRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(RegistryHandler.LEAD_NUGGET_ENTITY.get(), LeadNuggetRenderer::new);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/gleep/oreganized/armors/STABase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.util.List;

public class STABase extends ArmorItem {
//Maximum durability of the tint
public static final int MAX_TINT_DURABILITY = 50;
private final boolean immuneToFire;
//Used for tinted durability
private boolean shouldDisplayTint;

public STABase(IArmorMaterial materialIn, EquipmentSlotType slot) {
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/me/gleep/oreganized/blocks/StoneSign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package me.gleep.oreganized.blocks;

import me.gleep.oreganized.util.RegistryHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockReader;
import org.jetbrains.annotations.Nullable;

public class StoneSign extends Block {
private static final IntegerProperty PROGRESS = IntegerProperty.create("progress", 0, 8);;

public StoneSign(Properties properties) {
super(properties);
setDefaultState(this.getDefaultState().with(PROGRESS, 0));
}

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(PROGRESS);
}

/**
* Called throughout the code as a replacement for block instanceof BlockContainer
* Moving this to the Block base class allows for mods that wish to extend vanilla
* blocks, and also want to have a tile entity on that block, may.
* <p>
* Return true from this function to specify this block has a tile entity.
*
* @param state State of the current block
* @return True if block has a tile entity, false otherwise
*/
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}

/**
* Called throughout the code as a replacement for ITileEntityProvider.createNewTileEntity
* Return the same thing you would from that function.
* This will fall back to ITileEntityProvider.createNewTileEntity(World) if this block is a ITileEntityProvider
*
* @param state The state of the current block
* @param world The world to create the TE in
* @return A instance of a class extending TileEntity
*/
@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return RegistryHandler.STONE_SIGN_TE.get().create();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package me.gleep.oreganized.entities.entityrenderer;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import java.util.List;

import me.gleep.oreganized.blocks.StoneSign;
import me.gleep.oreganized.entities.tileentities.StoneSignTileEntity;
import net.minecraft.block.AbstractSignBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.StandingSignBlock;
import net.minecraft.block.WallSignBlock;
import net.minecraft.block.WoodType;
import net.minecraft.block.material.Material;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.Atlases;
import net.minecraft.client.renderer.BlockModelRenderer;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.model.Model;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.client.renderer.model.RenderMaterial;
import net.minecraft.client.renderer.texture.NativeImage;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.tileentity.SignTileEntity;
import net.minecraft.util.IReorderingProcessor;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.generators.BlockModelBuilder;

@OnlyIn(Dist.CLIENT)
public class StoneSignRenderer extends TileEntityRenderer<StoneSignTileEntity> {
public StoneSignRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);
}

@Override
public void render(StoneSignTileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
BlockState blockstate = tileEntityIn.getBlockState();
matrixStackIn.push();
float f = 0.6666667F;
matrixStackIn.translate(0.5D, 0.5D, 0.5D);
matrixStackIn.translate(0.0D, -0.3125D, 0.5D);

matrixStackIn.push();
matrixStackIn.scale(0.6666667F, -0.6666667F, -0.6666667F);
matrixStackIn.pop();
FontRenderer fontrenderer = this.renderDispatcher.getFontRenderer();
float f2 = 0.010416667F;
matrixStackIn.translate(0.0D, (double)0.33333334F, 0.04D);
matrixStackIn.scale(0.010416667F, -0.010416667F, 0.010416667F);
int i = tileEntityIn.getTextColor().getTextColor();
double d0 = 0.4D;
int j = (int)((double)NativeImage.getRed(i) * 0.4D);
int k = (int)((double)NativeImage.getGreen(i) * 0.4D);
int l = (int)((double)NativeImage.getBlue(i) * 0.4D);
int i1 = NativeImage.getCombined(0, l, k, j);
int j1 = 20;

for(int k1 = 0; k1 < 6; ++k1) {
IReorderingProcessor ireorderingprocessor = tileEntityIn.func_242686_a(k1, (p_243502_1_) -> {
List<IReorderingProcessor> list = fontrenderer.trimStringToWidth(p_243502_1_, 80);
return list.isEmpty() ? IReorderingProcessor.field_242232_a : list.get(0);
});
if (ireorderingprocessor != null) {
float f3 = (float)(-fontrenderer.func_243245_a(ireorderingprocessor) / 2);
fontrenderer.func_238416_a_(ireorderingprocessor, f3, (float)(k1 * 10 - 20), i1, false, matrixStackIn.getLast().getMatrix(), bufferIn, false, 0, combinedLightIn);
}
}

matrixStackIn.pop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package me.gleep.oreganized.entities.tileentities;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.function.Function;
import javax.annotation.Nullable;

import me.gleep.oreganized.util.RegistryHandler;
import net.minecraft.block.BlockState;
import net.minecraft.command.CommandSource;
import net.minecraft.command.ICommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.DyeColor;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.IReorderingProcessor;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentUtils;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;

public class StoneSignTileEntity extends TileEntity {
private final ITextComponent[] signText = new ITextComponent[]{StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY};
private boolean isEditable = true;
private PlayerEntity player;
private final IReorderingProcessor[] renderText = new IReorderingProcessor[6];
private DyeColor textColor = DyeColor.BLACK;

public StoneSignTileEntity() {
super(RegistryHandler.STONE_SIGN_TE.get());
}

@NotNull
@Override
public CompoundNBT write(CompoundNBT compound) {
super.write(compound);

for(int i = 0; i < 6; ++i) {
String s = ITextComponent.Serializer.toJson(this.signText[i]);
compound.putString("Text" + (i + 1), s);
}

compound.putString("Color", this.textColor.getTranslationKey());
return compound;
}

@Override
public void read(BlockState state, CompoundNBT nbt) {
this.isEditable = false;
super.read(state, nbt);
this.textColor = DyeColor.byTranslationKey(nbt.getString("Color"), DyeColor.BLACK);

for(int i = 0; i < 6; ++i) {
String s = nbt.getString("Text" + (i + 1));
ITextComponent itextcomponent = ITextComponent.Serializer.getComponentFromJson(s.isEmpty() ? "\"\"" : s);
if (this.world instanceof ServerWorld) {
try {
this.signText[i] = TextComponentUtils.func_240645_a_(this.getCommandSource((ServerPlayerEntity)null), itextcomponent, (Entity)null, 0);
} catch (CommandSyntaxException commandsyntaxexception) {
this.signText[i] = itextcomponent;
}
} else {
this.signText[i] = itextcomponent;
}

this.renderText[i] = null;
}

}

@OnlyIn(Dist.CLIENT)
public ITextComponent getText(int line) {
return this.signText[line];
}

public void setText(int line, ITextComponent signText) {
this.signText[line] = signText;
this.renderText[line] = null;
}

@Nullable
@OnlyIn(Dist.CLIENT)
public IReorderingProcessor func_242686_a(int p_242686_1_, Function<ITextComponent, IReorderingProcessor> p_242686_2_) {
if (this.renderText[p_242686_1_] == null && this.signText[p_242686_1_] != null) {
this.renderText[p_242686_1_] = p_242686_2_.apply(this.signText[p_242686_1_]);
}

return this.renderText[p_242686_1_];
}

/**
* Retrieves packet to send to the client whenever this Tile Entity is resynced via World.notifyBlockUpdate. For
* modded TE's, this packet comes back to you clientside in {@link #onDataPacket}
*/
@Nullable
@Override
public SUpdateTileEntityPacket getUpdatePacket() {
return new SUpdateTileEntityPacket(this.pos, 9, this.getUpdateTag());
}

/**
* Get an NBT compound to sync to the client with SPacketChunkData, used for initial loading of the chunk or when
* many blocks change at once. This compound comes back to you clientside in {@link handleUpdateTag}
*/
@Override
public CompoundNBT getUpdateTag() {
return this.write(new CompoundNBT());
}

/**
* Checks if players can use this tile entity to access operator (permission level 2) commands either directly or
* indirectly, such as give or setblock. A similar method exists for entities at {@link
* net.minecraft.entity.Entity#ignoreItemEntityData()}.<p>For example, {@link
* net.minecraft.tileentity.TileEntitySign#onlyOpsCanSetNbt() signs} (player right-clicking) and {@link
* net.minecraft.tileentity.TileEntityCommandBlock#onlyOpsCanSetNbt() command blocks} are considered
* accessible.</p>@return true if this block entity offers ways for unauthorized players to use restricted commands
*/
@Override
public boolean onlyOpsCanSetNbt() {
return true;
}

public boolean getIsEditable() {
return this.isEditable;
}

/**
* Sets the sign's isEditable flag to the specified parameter.
*/
@OnlyIn(Dist.CLIENT)
public void setEditable(boolean isEditableIn) {
this.isEditable = isEditableIn;
if (!isEditableIn) {
this.player = null;
}

}

public void setPlayer(PlayerEntity playerIn) {
this.player = playerIn;
}

public PlayerEntity getPlayer() {
return this.player;
}

public boolean executeCommand(PlayerEntity playerIn) {
for(ITextComponent itextcomponent : this.signText) {
Style style = itextcomponent == null ? null : itextcomponent.getStyle();
if (style != null && style.getClickEvent() != null) {
ClickEvent clickevent = style.getClickEvent();
if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) {
playerIn.getServer().getCommandManager().handleCommand(this.getCommandSource((ServerPlayerEntity)playerIn), clickevent.getValue());
}
}
}

return true;
}

public CommandSource getCommandSource(@Nullable ServerPlayerEntity playerIn) {
String s = playerIn == null ? "StoneSign" : playerIn.getName().getString();
ITextComponent itextcomponent = (ITextComponent)(playerIn == null ? new StringTextComponent("StoneSign") : playerIn.getDisplayName());
return new CommandSource(ICommandSource.DUMMY, Vector3d.copyCentered(this.pos), Vector2f.ZERO, (ServerWorld)this.world, 2, s, itextcomponent, this.world.getServer(), playerIn);
}

public DyeColor getTextColor() {
return this.textColor;
}
}
12 changes: 4 additions & 8 deletions src/main/java/me/gleep/oreganized/events/ModEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.gleep.oreganized.tools.STSBase;
import me.gleep.oreganized.util.ModDamageSource;
import me.gleep.oreganized.util.RegistryHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -168,14 +169,9 @@ public static void onBlockDestroyed(BlockEvent.BreakEvent event) {
ItemStack currentitem = event.getPlayer().inventory.getCurrentItem();

if (currentitem.getItem().equals(RegistryHandler.BUSH_HAMMER.get())) {
if (event.getPlayer().isSneaking()) {

} else {
if (state.getBlock().equals(Blocks.STONE)) {
world.setBlockState(pos, Blocks.COBBLESTONE.getDefaultState(), 2);
event.setCanceled(true);
} else if (state.getBlock().equals(Blocks.STONE_BRICKS)) {
world.setBlockState(pos, Blocks.CRACKED_STONE_BRICKS.getDefaultState(), 2);
for (Block b : BushHammer.EFFECTIVE_ON.keySet()) {
if (state.getBlock().equals(b)) {
world.setBlockState(pos, BushHammer.EFFECTIVE_ON.get(b).getDefaultState(), 2);
event.setCanceled(true);
}
}
Expand Down
Loading

0 comments on commit 4982e94

Please sign in to comment.